#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
static const int maxn = 100010;
long long val[maxn], m, n, inv2, inv6, invn, sum, sumsqr;
set<long long> diff;
bool vis[maxn];
inline long long pw(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
inline long long f(long long x, long long d) {
  return ((n * x % m * x % m +
           n * (n - 1) % m * (2 * n - 1) % m * d % m * d % m * inv6 % m) %
              m +
          n * (n - 1) % m * d % m * x % m) %
         m;
}
int main() {
  read(m);
  read(n);
  invn = pw(n, m - 2);
  inv2 = pw(2, m - 2);
  inv6 = pw(6, m - 2);
  for (int i = 1; i <= n; i++) {
    read(val[i]);
    (sum += val[i]) %= m;
    (sumsqr += (val[i] * val[i] % m)) %= m;
  }
  if (n == 1) {
    printf("%lld 1\n", val[1]);
    return 0;
  }
  sort(val + 1, val + n + 1);
  for (int i = 1; i <= min(10, (int)n - 1); i++)
    for (int j = i + 1; j <= n; j++) diff.insert(val[j] - val[i]);
  for (set<long long>::iterator it = diff.begin(); it != diff.end(); it++) {
    long long d = *it;
    long long fst =
        ((sum - (n * (n - 1) % m * d % m * inv2 % m)) % m + m) % m * invn % m;
    int pos = lower_bound(val + 1, val + n + 1, fst) - val;
    if (val[pos] != fst) continue;
    if (f(fst, d) == sumsqr) {
      memset(vis, 0, sizeof vis);
      long long nxt, lst = fst;
      while (1) {
        if (vis[pos]) break;
        vis[pos] = 1;
        nxt = (lst + d) % m;
        int p = lower_bound(val + 1, val + n + 1, nxt) - val;
        if (val[p] != nxt) break;
        lst = nxt;
        pos = p;
      }
      bool all = 1;
      for (int i = 1; i <= n; i++)
        if (!vis[i]) {
          all = 0;
          break;
        }
      if (all) {
        printf("%lld %lld\n", fst, d);
        return 0;
      }
    }
  }
  puts("-1");
  return 0;
}
