#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int mod = 1000000007;
const int inf = 2012345678;
const long long infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
const int N = 100010;
int a[N];
int b[N];
int po(int n, int e, int p) {
  if (!e) return 1;
  int t = po(n, e / 2, p);
  t = (long long)t * t % p;
  if (e & 1) t = (long long)t * n % p;
  return t;
}
int main() {
  freopen("input.txt", "r", stdin);
  int m, n;
  scanf("%d%d", &(m), &(n));
  for (int i = 0; i < (n); i++) scanf("%d", &(a[i]));
  set<int> s;
  for (int i = 0; i < (n); i++) {
    s.insert(a[i]);
  }
  if (n == 1) {
    printf("%d %d\n", a[0], 0);
    return 0;
  }
  if (n == m) {
    printf("%d %d\n", 0, 1);
    return 0;
  }
  long long sum = 0, sqsum = 0;
  for (int i = 0; i < (n); i++) {
    sum += a[i];
    sqsum += (long long)a[i] * a[i];
    sum = sum % m;
    sqsum = sqsum % m;
  }
  long long c1 = (long long)n * (n - 1) / 2 % m;
  long long c2 = (long long)n * (n - 1) * (2 * n - 1) / 6 % m;
  long long ic1 = po((int)c1, m - 2, m);
  for (int i = 0; i < (n); i++) {
    int x = a[i];
    long long c1d = sum - (long long)n * x;
    c1d = c1d % m;
    if (c1d < 0) c1d += m;
    int d = (int)(c1d * ic1 % m);
    if (d == 0) continue;
    long long check = 0;
    long long tmp = 0;
    tmp = (long long)n * x % m * x % m;
    check += tmp;
    tmp = 2LL * x * d % m * c1 % m;
    check += tmp;
    tmp = (long long)c2 * d % m * d % m;
    check += tmp;
    check = check % m;
    if (sqsum != check) continue;
    bool bad = false;
    for (int j = 0; j < (n); j++) {
      if (s.find((x + (long long)j * d) % m) == s.end()) {
        bad = true;
        break;
      }
    }
    if (bad) continue;
    printf("%d %d\n", x, d);
    return 0;
  }
  puts("-1");
  return 0;
}
