#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int b[maxn];
int fp(int a, int n, int m) {
  int res = 1;
  int tem = a;
  while (n) {
    if (n & 1) res = 1LL * res * tem % m;
    tem = 1LL * tem * tem % m;
    n >>= 1;
  }
  return res;
}
int main() {
  int n, m;
  cin >> m >> n;
  int i;
  int s[2];
  s[0] = s[1] = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s[0] = (a[i] + s[0]) % m;
    s[1] = (s[1] + 1LL * a[i] * a[i] % m) % m;
  }
  if (n == 1) return 0 * printf("%d 0\n", a[0]);
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    int d = (a[i] - a[0]);
    int x =
        (s[0] - 1LL * n * (n - 1) / 2 % m * d % m + m) * fp(n, m - 2, m) % m;
    int tem = 1LL * n * x % m * x % m;
    tem = (tem + 1LL * n * (n - 1) % m * d % m * x % m) % m;
    tem = (tem + 1LL * n * (n - 1) * (2 * n - 1) / 6 % m * d % m * d % m) % m;
    if (s[1] == tem) {
      b[0] = x;
      for (int i = 1; i < n; i++) {
        b[i] = (b[i - 1] + d) % m;
      }
      sort(b, b + n);
      bool isok = true;
      for (int i = 0; i < n; i++) isok &= (a[i] == b[i]);
      if (isok) return 0 * printf("%d %d\n", x, d);
    }
  }
  printf("-1\n");
  return 0;
}
