#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
long long mod_pow(long long x, long long n, long long p) {
  long long res = 1;
  x %= p;
  while (n > 0) {
    if (n & 1) res = res * x % p;
    x = x * x % p;
    n >>= 1;
  }
  return res;
}
long long mod_inv(long long x, long long p) { return mod_pow(x % p, p - 2, p); }
long long mod_sqrt(long long x, long long p) {
  x %= p;
  if (x == 0) return 0;
  if (p == 2) return x;
  auto is_square = [&](long long a) { return mod_pow(a, (p - 1) / 2, p) == 1; };
  if (!is_square(x)) return -1;
  long long y = 2;
  while (is_square((y * y - x + p) % p)) y++;
  long long r = (y * y - x + p) % p;
  auto mul = [&](pair<long long, long long> u, pair<long long, long long> v) {
    long long s = (u.first * v.first + u.second * v.second % p * r) % p;
    long long t = (u.second * v.first + u.first * v.second) % p;
    return make_pair((s), (t));
  };
  long long e = (p + 1) / 2;
  auto ret = make_pair((1LL), (0LL));
  auto v = make_pair((y), (1LL));
  while (e > 0) {
    if (e & 1) ret = mul(ret, v);
    v = mul(v, v);
    e /= 2;
  }
  assert(r == 0 || ret.second == 0);
  return ret.first;
}
int main() {
  long long m, n;
  cin >> m >> n;
  vector<long long> vec(n);
  for (int i = (int)(0); i < (int)(n); i++) scanf("%d", &vec[i]);
  set<long long> st;
  for (int i = (int)(0); i < (int)(n); i++) st.insert(vec[i]);
  if (n == 1) {
    cout << vec[0] << " " << 0;
    return 0;
  }
  if (m < n) {
    cout << -1 << endl;
    return 0;
  }
  if (m == n) {
    cout << vec[0] << " " << 1 << endl;
    return 0;
  }
  if (n == m - 1) {
    for (int i = (int)(0); i < (int)(m); i++)
      if (st.find(i) == st.end()) {
        cout << (i + 1) % m << " " << 1 << endl;
        return 0;
      }
  }
  long long s = accumulate((vec).begin(), (vec).end(), 0LL);
  long long avg = s % m * mod_inv(n, m) % m;
  long long v = 0;
  for (int i = (int)(0); i < (int)(n); i++)
    v += (vec[i] - avg) * (vec[i] - avg) % m;
  v = v % m * mod_inv(n, m) % m;
  long long d = mod_sqrt(12 * v % m * mod_inv(n * n - 1, m) % m, m);
  if (d <= 0) {
    cout << -1 << endl;
    return 0;
  }
  int tmp = vec[0];
  int cnt = 1;
  while (cnt < n && st.find((tmp + d) % m) != st.end()) {
    tmp = (tmp + d) % m;
    cnt++;
  }
  tmp = vec[0];
  while (cnt < n && st.find((tmp - d + m) % m) != st.end()) {
    tmp = (tmp - d + m) % m;
    cnt++;
  }
  if (cnt == n) {
    cout << tmp << " " << d << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
