#include <bits/stdc++.h>
using namespace std;
int n, p, s[100005], sum, sqs;
int po(int a, int b) {
  int c = 1, d = a;
  while (b) {
    if (b & 1) c = 1LL * c * d % p;
    d = 1LL * d * d % p;
    b >>= 1;
  }
  return c;
}
int inv(int x) { return po(x, p - 2); }
map<int, bool> M;
int main() {
  scanf("%d %d", &p, &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &s[i]);
  if (n == 1) {
    printf("%d 0\n", s[1]);
    return 0;
  }
  if (n == p) {
    printf("0 1\n");
    return 0;
  }
  for (int i = (1); i <= (n); i++) {
    sum = (sum + s[i]) % p;
    sqs = (sqs + 1LL * s[i] * s[i]) % p;
    M[s[i]] = true;
  }
  for (int i = (1); i <= (n); i++) {
    int x = s[i];
    int d = ((sum - 1LL * n * x) % p + p) % p;
    d = 1LL * d * inv((1LL * n * (n - 1) / 2) % p) % p;
    if (d == 0) continue;
    int qs = (1LL * n * x % p * x % p + 1LL * n * (n - 1) % p * x % p * d % p +
              1LL * (n - 1) * n * (2 * n - 1) / 6 % p * d % p * d % p) %
             p;
    if (qs != sqs) continue;
    int cur = x;
    for (int j = (1); j <= (n); j++) {
      if (!M.count(cur)) goto gg;
      cur += d;
      if (cur >= p) cur -= p;
    }
    printf("%d %d\n", x, d);
    return 0;
  gg:;
  }
  printf("-1\n");
  return 0;
}
