#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
int n;
long long m, a[maxN], b[maxN], c[maxN], x, d;
bool fr[maxN];
long long power(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) {
      r = r * a % m;
    }
    b /= 2;
    a = a * a % m;
  }
  return r;
}
int Try(int index) {
  long long sum = 0;
  for (int i = 1; i <= (int)(n); ++i) {
    b[i] = (a[i] - a[index] + m) % m;
    sum = (sum + b[i]) % m;
    fr[i] = 0;
  }
  multimap<long long, int> mp;
  for (int i = 1; i <= (int)(n); ++i) {
    if (i == index) {
      fr[i] = 1;
      continue;
    }
    auto it = mp.find(m - b[i]);
    if (it == mp.end()) {
      mp.emplace(b[i], i);
    } else {
      fr[i] = fr[it->second] = 1;
      mp.erase(it);
    }
  }
  int f = count(fr + 1, fr + n + 1, 1);
  if (f == n) {
    return 0;
  }
  long long h = 0;
  for (int i = 1, j = (f - 1) / 2 + 1; i <= n - f; ++i) {
    h += j;
    ++j;
  }
  h %= m;
  long long dd = sum * power(h, m - 2) % m;
  for (int i = 1, j = -(f - 1) / 2; i <= n; ++i, ++j) {
    c[i] = (j * dd % m + m) % m;
  }
  long long xx = (c[1] + a[index]) % m;
  sort(b + 1, b + n + 1);
  sort(c + 1, c + n + 1);
  for (int i = 1; i <= (int)(n); ++i) {
    if (b[i] != c[i]) {
      return -1;
    }
  }
  d = dd;
  x = xx;
  return 1;
}
void solve() {
  cin >> m >> n;
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> a[i];
  }
  map<long long, int> mp;
  for (int i = 1; i <= (int)(n); ++i) {
    ++mp[a[i]];
  }
  if ((int)mp.size() == 1) {
    cout << a[1] << ' ' << 0;
    return;
  }
  if (m > n && (int)mp.size() < n) {
    cout << -1;
    return;
  }
  if (m <= n) {
    if ((int)mp.size() < m) {
      cout << -1;
      return;
    }
    vector<int> e;
    for (auto &p : mp) {
      e.emplace_back(p.second);
    }
    sort((e).begin(), (e).end());
    e.resize(unique((e).begin(), (e).end()) - e.begin());
    if ((int)e.size() >= 3) {
      cout << -1;
      return;
    }
    n = 0;
    if ((int)e.size() == 1) {
      cout << a[1] << ' ' << 1;
      return;
    } else {
      for (auto &p : mp) {
        if (p.second > e[0]) {
          a[++n] = p.first;
        }
      }
    }
  }
  int ok = 0;
  if (n * 2 > m) {
    set<int> st;
    for (int i = 1; i <= (int)(n); ++i) {
      st.emplace(a[i]);
    }
    n = 0;
    for (int i = 0; i < (int)(m); ++i) {
      if (!st.count(i)) {
        a[++n] = i;
      }
    }
    if (n == 1) {
      x = a[1], d = 1, ok = 1;
    } else {
      int idx = 0;
      while (ok == 0) {
        ok = Try(++idx);
      }
    }
    x = (x + n * d) % m;
  } else {
    int idx = 0;
    while (ok == 0) {
      ok = Try(++idx);
    }
  }
  if (ok == 1) {
    cout << x << ' ' << d;
  } else {
    cout << -1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
