#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Print() { cout << endl; }
template <typename T1, typename... T>
void Print(const T1 &t1, const T &...t) {
  cout << t1 << " ";
  Print(t...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class Iterator>
ostream &output_cantainer(ostream &os, Iterator first, Iterator last,
                          bool space = true) {
  if (space) {
    for (Iterator it = first; it != last; it++) {
      os << (*it) << ' ';
    }
    os << endl;
  } else
    for (Iterator it = first; it != last; it++) {
      os << (*it) << endl;
    }
  return os;
}
const int N = 1e5 + 4;
int a[N], m, n;
int s, x, d;
unordered_set<int> hs;
int fastpow(int a, int e, int m) {
  if (e == 0) return 1 % m;
  if (e == 1) return a % m;
  LL t = fastpow(a, e / 2, m);
  t *= t;
  t %= m;
  if (e & 1) t *= a % m;
  return t % m;
}
bool solve() {
  int s = 0, base = 0, ssq = 0;
  if (n == 1) {
    x = a[1];
    d = 0;
    return true;
  }
  if (n % 2 == 1) {
    for (int i = 1; i <= n; i++) s = (s + a[i]) % m;
    base = 1ll * s * fastpow(n, m - 2, m) % m;
    if (!hs.count(base)) return false;
    for (int i = 1; i <= n; i++)
      ssq = (ssq + 1ll * (a[i] - base + m) % m * (a[i] - base + m) % m) % m;
    int t = n / 2,
        c = 1ll * t * (t + 1) % m * (2 * t + 1) % m * fastpow(3, m - 2, m) % m;
    for (int i = 1; i <= n; i++) {
      if (1ll * c * (a[i] - base + m) % m * (a[i] - base + m) % m == ssq) {
        bool found = true;
        int l = base, r = base;
        for (int j = 1; found && j <= t; j++) {
          l -= (a[i] - base + m) % m;
          r += (a[i] - base + m) % m;
          l = (l + m) % m;
          r %= m;
          if (!hs.count(l) || !hs.count(r)) found = false;
        }
        if (found) {
          x = (base - 1ll * t * (a[i] - base + m) % m + m) % m;
          d = (a[i] - base + m) % m;
          return true;
        }
      }
    }
    return false;
  }
  if (n % 2 == 0) {
    for (int i = 1; i <= n; i++) s = (s + a[i]) % m;
    base = 1ll * s * fastpow(n, m - 2, m) % m;
    for (int i = 1; i <= n; i++)
      ssq = (ssq + 1ll * (a[i] - base + m) % m * (a[i] - base + m) % m) % m;
    int t = n / 2, c = 1ll * (2 * t - 1) % m * (2 * t) % m * (2 * t + 1) % m *
                       fastpow(3, m - 2, m) % m;
    for (int i = 1; i <= n; i++) {
      if (1ll * c * (a[i] - base + m) % m * (a[i] - base + m) % m == ssq) {
        bool found = true;
        int l = (2 * base % m - a[i] + m) % m, r = a[i];
        for (int j = 1; found && j <= t; j++) {
          if (!hs.count(l) || !hs.count(r)) found = false;
          l -= (a[i] - base + m) % m * 2 % m;
          r += (a[i] - base + m) % m * 2 % m;
          l = (l + m) % m;
          r %= m;
        }
        if (found) {
          d = (a[i] - base + m) % m * 2 % m;
          x = (a[i] - 1ll * t * d % m + m) % m;
          return true;
        }
      }
    }
    return false;
  }
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    hs.insert(a[i]);
  }
  if (!solve()) {
    puts("-1");
  } else {
    printf("%d %d\n", x, d);
  }
}
