#include <bits/stdc++.h>
using namespace std;
const int maxn = 100006;
int mm(int n, int m, int mod) {
  long long s = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      s = s * k;
      s %= mod;
    }
    k = k * k;
    k %= mod;
    m >>= 1;
  }
  return s;
}
int sum;
int sum2;
int n, m;
int a[maxn];
int b[maxn];
bool check(int x, int d) {
  int ans = (((long long)x * x % m * n % m) +
             ((long long)n * (n - 1) % m * d % m * x % m) +
             ((long long)(n - 1) * (n) * (2 * n - 1) / 6 % m * d % m * d % m)) %
            m;
  if (ans != sum2) return 0;
  for (int i = 1; i <= n; i++) b[i] = (x + (long long)(i - 1) * d) % m;
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  cin >> m >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    sum2 += (long long)a[i] * a[i] % m;
    sum2 %= m;
    sum %= m;
  }
  if (n == m) {
    printf("0 1\n");
    return 0;
  }
  if (n > m) {
    printf("-1\n");
    return 0;
  }
  if (n == 1) {
    printf("%d 0\n", a[1]);
    return 0;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    int d = (sum - (long long)n * a[i]) % m;
    d = (d + m) % m;
    d = (long long)d * mm((long long)n * (n - 1) / 2 % m, m - 2, m) % m;
    if (check(a[i], d)) {
      cout << a[i] << " " << d << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
