#include <bits/stdc++.h>
using namespace std;
int a[500001], num[500001];
int n, mod;
long long sum;
inline int add(int a, int b) { return a + b - mod >= 0 ? a + b - mod : a + b; }
inline int mul(int a, int b) { return (long long)a * b % mod; }
int power(int a, int b) {
  int ret = 1;
  for (int t = a; b; b >>= 1) {
    if (b & 1) ret = mul(ret, t);
    t = mul(t, t);
  }
  return ret;
}
int calD() {
  long long t = (long long)n * (n + 1) * (n - 1) / 6;
  int x = n & 1 ? mul(t / 2 % mod, n) : mul(t % mod, n / 2);
  int y = sum % mod;
  y = (-mul(y, y) + mod) % mod;
  for (int i = 0; i < n; i++) y = add(y, mul(mul(a[i], a[i]), n));
  if (x) {
    int d2 = mul(y, power(x, mod - 2));
    for (int i = 0; i < n; i++) {
      int d = a[i] - a[0];
      if (mul(d, d) == d2) return d;
    }
    return -1;
  }
  if (y) return -1;
  return a[n - 1] - a[0];
}
int calX(int d) {
  if (d == -1) return -1;
  long long t = sum - (long long)n * (n - 1) * d / 2;
  t = ((t % mod) + mod) % mod;
  if (n % mod == 0) return t % n == 0 ? t / n : -1;
  return mul(t, power(n, mod - 2));
}
bool check(int d, int x) {
  if (x == -1) return false;
  static int b[500001];
  for (int i = 0; i < n; i++, x = add(x, d)) b[i] = x;
  sort(b, b + n);
  return memcmp(a, b, sizeof(int) * n) == 0;
}
int main() {
  scanf("%d%d", &mod, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  sort(a, a + n);
  int d = calD(), x = calX(d);
  if (check(d, x))
    printf("%d %d", x, d);
  else
    printf("-1");
}
