#include <bits/stdc++.h>
using namespace std;
long long pr = 1000000009;
long long exp(long long b, long long e) {
  long long ans = 1;
  while (e) {
    if (e % 2) {
      ans = (ans * b) % pr;
    }
    e /= 2;
    b = (b * b) % pr;
  }
  return ans;
}
long long inv(long long a) { return exp(a, pr - 2); }
int main() {
  ios::sync_with_stdio(false);
  vector<int> A, B;
  int n, h;
  cin >> pr;
  cin >> n;
  map<int, int> used;
  int max1 = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    h = a;
    max1 = max(max1, ++used[a]);
  }
  if (n == 1) {
    cout << h << ' ' << 1 << '\n';
    return 0;
  }
  if (max1 == n) {
    cout << h << ' ' << 0 << '\n';
    return 0;
  }
  if (pr == 2) {
    if (abs(used[0] - used[1]) > 1) {
      cout << -1 << '\n';
      return 0;
    }
    if (used[0] > used[1]) {
      cout << 0 << ' ' << 1 << '\n';
      return 0;
    } else {
      cout << 1 << ' ' << 1 << '\n';
      return 0;
    }
  }
  if (max1 > 1) {
    for (int i = 0; i < pr; i++) {
      if (used[i] == 0) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  for (map<int, int>::iterator it = used.begin(); it != used.end(); it++) {
    pair<int, int> now = *it;
    if (now.second == max1) {
      A.push_back(now.first);
      A.push_back(now.first + pr);
    } else if (now.second != max1 - 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  int flag = 0;
  if (A.size() > pr) {
    A.clear();
    flag = 1;
    for (int i = 0; i < pr; i++) {
      if (used[i] != max1) {
        A.push_back(i);
        A.push_back(i + pr);
      }
    }
  }
  int n1 = A.size() / 2;
  sort(A.begin(), A.end());
  long long d, buf = h;
  if (n1 <= 1)
    d = 1;
  else {
    int st = 0, end = 1, diff = A[1] - A[0], nof = 0;
    while (st < n1) {
      if (A[end] - A[st] >= diff) {
        if (A[end] - A[st] == diff) {
          nof++;
        }
        st++;
      } else
        end++;
    }
    d = (diff * inv(n1 - nof)) % pr;
  }
  buf = h;
  int forw = 0, back = 0;
  used[buf]--;
  for (int i = 1;; i++) {
    int fl = 0;
    if (used[((long long)buf + i * d) % pr] > 0) {
      forw++;
      used[((long long)buf + i * d) % pr]--;
    } else
      break;
  }
  for (int i = 1;; i++) {
    if (used[(((long long)buf - i * d) % pr + pr) % pr] > 0) {
      back++;
      used[(((long long)buf - i * d) % pr + pr) % pr]--;
    } else
      break;
  }
  if (forw + back + 1 == n)
    cout << ((buf - back * d) % pr + pr) % pr << ' ' << d << '\n';
  else
    cout << -1 << '\n';
  return 0;
};
