using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 5 2");
WillReturn.Add("1 3");
WillReturn.Add("4 2");
//(2,5)
//(3,5)
//(4,5)
//(5,3)
//(5,4)
//(5,5)
}
else if (InputPattern == "Input2") {
WillReturn.Add("5 5 5");
WillReturn.Add("1 1");
WillReturn.Add("1 3");
WillReturn.Add("3 3");
WillReturn.Add("3 4");
WillReturn.Add("4 3");
//-1
}
else if (InputPattern == "Input3") {
WillReturn.Add("5 5 2");
WillReturn.Add("3 2");
WillReturn.Add("4 3");
//-1
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static int mH;
static int mW;
struct PointDef
{
internal int X;
internal int Y;
}
static List<PointDef> mPointList = new List<PointDef>();
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => int.Parse(pX)).ToArray();
SplitAct(InputList[0]);
mH = wkArr[0];
mW = wkArr[1];
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
PointDef WillAdd;
WillAdd.X = wkArr[0];
WillAdd.Y = wkArr[1];
mPointList.Add(WillAdd);
}
var AnswerSet = new HashSet<PointDef>();
for (int LoopX = 1; LoopX <= mW; LoopX++) {
if (IsOKPoint(LoopX, mH)) {
AnswerSet.Add(new PointDef() { X = LoopX, Y = mH });
}
}
for (int LoopY = 1; LoopY <= mH; LoopY++) {
if (IsOKPoint(mW, LoopY)) {
AnswerSet.Add(new PointDef() { X = mW, Y = LoopY });
}
}
if (AnswerSet.Count == 0) {
Console.WriteLine(-1);
return;
}
foreach (PointDef EachPoint in AnswerSet.OrderBy(pX => pX.X).ThenBy(pX => pX.Y)) {
Console.WriteLine("({0},{1})", EachPoint.X, EachPoint.Y);
}
}
// 点の座標を引数として、イチゴを分割できるかを返す
static bool IsOKPoint(int pX, int pY)
{
// タンジェントが一致する点があったらNG
foreach (PointDef EachPoint in mPointList) {
if (EachPoint.Y * pX == EachPoint.X * pY) {
return false;
}
}
// タンジェントが小さい点の数
int LowerCnt = 0;
// タンジェントが大きい点の数
int GreaterCnt = 0;
foreach (PointDef EachPoint in mPointList) {
if (EachPoint.Y * pX < EachPoint.X * pY) {
LowerCnt++;
}
else {
GreaterCnt++;
}
}
return LowerCnt == GreaterCnt;
}
}