
object Main {

  def main(args: Array[String]) {

    val source = scala.io.Source.fromFile(args(0)).getLines.toSeq

    var index: Int = 0

    while(true) {

      val nm = source(index).split(" ").map(_.toInt)

      if (nm.forall(_ == 0))
        return

      println(calc(nm(0), nm(1), source.drop(index + 1).take(nm.sum)))

      index += nm.sum + 1

    }
  }

  def calc(n: Int, m: Int, inputs: Seq[String]) = {
    val taro = inputs.take(n).map(_.toInt).sorted
    val hana = inputs.drop(n).take(m).map(_.toInt).sorted

    val diff = taro.sum - hana.sum

    if (diff == 0) {
      taro.find(v => hana.contains(v)).map(v => s"${v} ${v}").getOrElse("-1")
    } else if (Math.abs(diff) % 2 == 1) {
      "-1"
    } else {
      (for (
        v1 <- taro;
        v2 <- hana;
        if v1 - v2 == diff / 2
      ) yield s"${v1} ${v2}").headOption.getOrElse("-1")
    }
  }

}