#include <bits/stdc++.h>
using namespace std;
const int MXN = 100005;
const int MOD = 1e9 + 7;
long long M, N, A[MXN];
vector<int> ip;
long long fpow(long long a, long long b, long long MD) {
  if (b == 0) return 1 % MD;
  long long r = fpow(a * a % MD, b / 2, MD);
  if (b & 1) r = r * a % MD;
  return r;
}
long long rev(long long x, long long MD) { return fpow(x, MD - 2, MD); }
bool validate(long long a, long long d) {
  vector<int> vec;
  for (int i = 0; i < (N); i++) {
    vec.push_back((a + i * d) % M);
  }
  sort(begin(vec), end(vec));
  return vec == ip;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> M >> N;
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    ip.push_back(A[i]);
  }
  sort(begin(ip), end(ip));
  long long sum2 = 0;
  long long i2 = 0;
  long long sum = 0;
  for (int i = 0; i < (N); i++) {
    sum2 += A[i] * A[i] % M;
    i2 += 1LL * i * i % M;
    sum += A[i];
  }
  sum %= M;
  sum2 %= M;
  i2 %= M;
  pair<long long, long long> ans(-1, -1);
  if (N == M) {
    ans = {0, 1};
  }
  for (int i = 0; i < (N); i++) {
    long long a1 = A[i];
    long long d = (sum - N * a1 % M + M) * 2 % M;
    d = d * rev(N, M) % M * rev(N - 1, M) % M;
    assert((a1 * N + (N - 1) * N % M * d % M * rev(2, M)) % M == sum);
    long long s2 = N * a1 % M * a1 % M;
    s2 += N * (N - 1 + M) % M * a1 % M * d % M;
    s2 += d * d % M * i2 % M;
    s2 %= M;
    if (s2 == sum2 and validate(a1, d)) {
      ans = {a1, d};
      break;
    }
  }
  if (ans.first == -1)
    cout << -1 << endl;
  else {
    cout << ans.first << " " << ans.second << endl;
    assert(validate(ans.first, ans.second));
  }
  return 0;
}
