#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, a[N], MOD;
int getIdx(int i) {
  int idx = 0;
  set<int> has;
  for (int(j) = (1); (j) <= (int)(n); (j)++) {
    auto it = has.find((a[j] - a[i] + MOD) % MOD);
    if (it != has.end()) {
      ++idx;
      has.erase(it);
    } else
      has.insert((a[i] - a[j] + MOD) % MOD);
  }
  return idx;
}
long long power(int b, int p) {
  if (!p) return 1;
  long long ret = power(b, p >> 1);
  return ret * ret % MOD * (p & 1 ? b : 1) % MOD;
}
pair<int, int> solve(int i, int j, int ii, int jj) {
  long long diff = (a[jj] - a[ii] + MOD) % MOD;
  long long d = diff * power((j - i + MOD) % MOD, MOD - 2) % MOD;
  long long x = (a[1] - i * d % MOD + MOD) % MOD;
  multiset<long long> has;
  for (int(i) = (1); (i) <= (int)(n); (i)++) has.insert(a[i]);
  long long temp = x;
  for (int(i) = (1); (i) <= (int)(n); (i)++) {
    auto it = has.find(temp);
    if (it == has.end()) return {-1, -1};
    has.erase(it);
    temp = (temp + d) % MOD;
  }
  return {x, d};
}
pair<int, int> solve() {
  if (n <= 1) return {a[1], 1};
  if (n == 2) return {a[1], (a[2] - a[1] + MOD) % MOD};
  int ii = 1, jj = 2;
  int i = getIdx(ii), j = getIdx(jj);
  pair<int, int> ret = solve(i, j, ii, jj);
  if (~ret.second) return ret;
  ret = solve(n - i - 1, j, ii, jj);
  if (~ret.second) return ret;
  ret = solve(i, n - j - 1, ii, jj);
  if (~ret.second) return ret;
  return ret = solve(n - i - 1, n - j - 1, ii, jj);
}
int main() {
  scanf("%d%d", &MOD, &n);
  for (int(i) = (1); (i) <= (int)(n); (i)++) scanf("%d", &a[i]);
  pair<int, int> ans;
  if (n * 2 > MOD) {
    multiset<long long> has;
    for (int(i) = (1); (i) <= (int)(n); (i)++) has.insert(a[i]);
    int realN = n;
    n = 0;
    for (int(i) = (0); (i) <= (int)(MOD - 1); (i)++)
      if (!has.count(i)) {
        a[++n] = i;
      }
    assert(2 * n <= MOD);
    ans = solve();
    ans.first = (ans.first - 1ll * realN * ans.second % MOD + MOD) % MOD;
  } else
    ans = solve();
  if (~ans.second)
    printf("%d %d\n", ans.first, ans.second);
  else
    printf("-1\n");
  return 0;
}
