#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

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;
ll m, a[maxN], b[maxN], c[maxN], x, d;
bool fr[maxN];

ll power(ll a, ll b)
{
    ll r = 1;
    while (b)
    {
        if (b & 1)
        {
            r = r * a % m;
        }
        b /= 2;
        a = a * a % m;
    }
    return r;
}

int Try(int index)
{
    ll sum = 0;
    for1(i, n)
    {
        b[i] = (a[i] - a[index] + m) % m;
        sum = (sum + b[i]) % m;
        fr[i] = 0;
    }
    multimap <ll, int> mp;
    for1(i, n)
    {
        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->se] = 1;
            mp.erase(it);
        }
    }
    int f = count(fr + 1, fr + n + 1, 1);
    if (f == n)
    {
        return 0;
    }
    ll h = 0;
    for (int i = 1, j = (f - 1) / 2 + 1; i <= n - f; ++i)
    {
        h += j;
        ++j;
    }
    h %= m;
    ll 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;
    }
    ll xx = (c[1] + a[index]) % m;
    sort(c + 1, c + n + 1);
    sort(b + 1, b + n + 1);
    for1(i, n)
    {
        if (b[i] != c[i])
        {
            return -1;
        }
    }
    d = dd;
    x = xx;
    return 1;
}

void solve()
{
    cin >> m >> n;
    for1(i, n)
    {
        cin >> a[i];
    }
    if (n == 1)
    {
        cout << a[1] << ' ' << 0;
        return;
    }
    int tmp = Try(1);
    if (tmp == 1)
    {
        cout << x << ' ' << d;
    }
    else if (tmp == -1)
    {
        cout << -1;
    }
    else
    {
        tmp = Try(2);
        if (tmp == 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;
}


#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

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;
ll m, a[maxN], b[maxN], c[maxN], x, d;
bool fr[maxN];

ll power(ll a, ll b)
{
    ll r = 1;
    while (b)
    {
        if (b & 1)
        {
            r = r * a % m;
        }
        b /= 2;
        a = a * a % m;
    }
    return r;
}

int Try(int index)
{
    ll sum = 0;
    for1(i, n)
    {
        b[i] = (a[i] - a[index] + m) % m;
        sum = (sum + b[i]) % m;
        fr[i] = 0;
    }
    multimap <ll, int> mp;
    for1(i, n)
    {
        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->se] = 1;
            mp.erase(it);
        }
    }
    int f = count(fr + 1, fr + n + 1, 1);
    if (f == n)
    {
        return 0;
    }
    ll h = 0;
    for (int i = 1, j = (f - 1) / 2 + 1; i <= n - f; ++i)
    {
        h += j;
        ++j;
    }
    h %= m;
    ll 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;
    }
    ll xx = (c[1] + a[index]) % m;
    sort(c + 1, c + n + 1);
    sort(b + 1, b + n + 1);
    for1(i, n)
    {
        if (b[i] != c[i])
        {
            return -1;
        }
    }
    d = dd;
    x = xx;
    return 1;
}

void solve()
{
    cin >> m >> n;
    for1(i, n)
    {
        cin >> a[i];
    }
    map <ll, int> mp;
    for1(i, n)
    {
        ++mp[a[i]];
    }
    //d = 0
    if ((int)mp.size() == 1)
    {
        cout << a[1] << ' ' << 0;
        return;
    }
    //d != 0
    if (m > n && (int)mp.size() < n)
    {
        cout << -1;
        return;
    }
    //m <= n
    if (m <= n)
    {
        if ((int)mp.size() < m)
        {
            cout << -1;
            return;
        }
        vi e;
        for (auto &p: mp)
        {
            e.eb(p.se);
        }
        sort(all(e));
        e.resize(unique(all(e)) - 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.se > e[0])
                {
                    a[++n] = p.fi;
                }
            }
        }
    }
    int tmp = Try(1);
    if (tmp == 0)
    {
        tmp = Try(2);
    }
    if (tmp == 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;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 100005
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
int a[MAX],s1,s2;

void fmain(int tid) {
    scanf("%d%d", &m, &n);
    REP(i,n) {
        scanf("%d", a+i); addmod(s1,a[i],m);
        addmod(s2, (ll)a[i]*a[i]%m,m);
    }
    sort(a,a+n);
    ll tn = (ll)n*(n-1)/2 %m, gg = (ll)n*(n-1)*(n+n-1)/6 %m;
    REP(i,n) {
        int d = (a[i]-a[0]+m)%m;
        int a1 = (ll)(s1-tn*d%m+m)%m * fastPow(n, m-2, m) % m;
        ll zp = (ll)n*a1%m*a1%m + gg*d%m*d%m + (ll)n*(n-1)%m*d%m*a1%m;
        zp %= m;
        if (zp == s2) {
            vector<int> b(n, 0);
            REP(j,n) b[j] = (a1+(ll)j*d%m)%m;
            sort(b.begin(),b.end());
            bool ok = 1;
            REP(j,n) if (a[j]!=b[j]) {
                ok=0; break;
            }
            if (ok) {
                printf("%d %d\n",a1,d);
                return;
            } else {
                puts("-1");
                return;
            }
        }
    }
    puts("-1");
}
int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 100005
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
int a[MAX],s1,s2;

void fmain(int tid) {
    scanf("%d%d", &m, &n);
    REP(i,n) {
        scanf("%d", a+i); addmod(s1,a[i],m);
        addmod(s2, (ll)a[i]*a[i]%m,m);
    }
    sort(a,a+n);
    ll tn = (ll)n*(n-1)/2 %m, gg = (ll)n*(n-1)*(n+n-1)/6 %m;
    REP(i,n) {
        int d = (a[i]-a[0]+m)%m;
        int a1 = (ll)(s1-tn*d%m+m)%m * fastPow(n, m-2, m) % m;
        ll zp = (ll)n*a1%m*a1%m + gg*d%m*d%m + (ll)n*(n-1)%m*d%m*a1%m;
        zp %= m;
        if (zp == s2) {
            vector<int> b(n, 0);
            REP(j,n) b[j] = (a1+(ll)j*d%m)%m;
            sort(b.begin(),b.end());
            bool ok = 1;
            REP(j,n) if (a[j]!=b[j]) {
                ok=0; break;
            }
            if (ok) {
                printf("%d %d\n",a1,d);
                return;
            }
        }
    }
    puts("-1");
}
int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long modpow(long long n, long long k, long long MOD) {
	long long ans = 1; n %= MOD;
	while (k > 0) {
		if (k & 1) ans = (ans*n) % MOD;
		k >>= 1; n = (n*n) % MOD;
	}
	return ans;
}

#define int long long

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int m, n; cin >> m >> n;
	set<int> a;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		a.insert(x);
	}
	if (n == 1) {
		cout << *a.begin() << ' ' << 1 << '\n';
		exit(0);
	} else if (n == m) {
		cout << "0 1\n";
		exit(0);
	} else if (n == m-1) {
		for (int i = 0; i < m; i++) {
			if (a.find(i) == a.end()) {
				cout << (i+1)%m << ' ' << 1 << '\n';
				exit(0);
			}
		}
	}

	int comple = 0;
	set<int> b;
	if (m < 2*n) {
		for (int i = 0; i < m; i++) {
			if (a.find(i) == a.end()) b.insert(i);
		}
		swap(a, b);
		comple = 1;
		n = a.size();
	}

	int diff = *a.rbegin() - *a.begin();
	int cnt = n;
	for (auto it = a.begin(); it != a.end(); it++) {
		cnt -= (a.find((*it + diff) % m) != a.end());
	}
	diff = (diff * modpow(cnt, m-2, m)) % m;

	if (comple) swap(a, b);
	b = a;

	int st = *a.begin();
	a.erase(a.begin());
	while (1) {
		int nxt = ((st - diff) % m + m) % m;
		if (a.find(nxt) == a.end()) break;
		st = nxt; a.erase(a.find(st));
	}

	int cur = st;
	while (1) {
		if (b.find(cur) == b.end()) {
			cout << "-1\n";
			exit(0);
		}
		b.erase(b.find(cur));
		if (b.empty()) break;
		cur = (cur + diff) % m;
	}
	cout << st << ' ' << diff << '\n';

 	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int n, m, a[100005];
set<int>st;
bool f = false;
int fast(int b, int e){
  int ret = 1;
  for(;e;e>>=1,b=1ll*b*b%m)
    if(e&1)
      ret=1ll*b*ret;
  return ret;
}
int getCnt(int d){
  int cnt = 0;
  f(i,0,n){
    cnt += st.count((a[i]+d)%m);
    cnt += st.count((a[i]+m-d)%m);
  }
  return cnt / 2;
}
int getFirst(int diff){
  int cnt = 0;
  int start = 0;
  f(i,0,n){
    if(st.count((a[i]+m-diff)%m))cnt++;
    else start = a[i];
  }
  if(cnt == n - 1)
    return start;
  return -1;
}
ii solve(){

  sort(a,a+n);

  int diff = a[1] - a[0];
  int cnt = n-getCnt(diff);
  int d = 1ll*diff*fast(cnt,m-2)%m;
//  cout<<diff<<' '<<d<<' '<<cnt<<'\n';
  auto x = getFirst(d);
  return make_pair(x,d);
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> m >> n;

  f(i,0,n){
    cin >> a[i];
    st.insert(a[i]);
  }

  if(2 * n > m){
    f = true;
    n = 0;
    f(i,0,m)
    if(st.count(i))st.erase(i);
    else {
      a[n++] = i;
      st.insert(i);
    }
  }

  if(!n){
    cout << "0 1\n";
    return 0;
  } else if(n == 1){
    if(!f)cout << a[0] << ' ' << 1 << '\n';
    else cout << (a[0] + 1) % m << ' ' << 1 << '\n';
    return 0;
  }

  auto x = solve();

  if(x.F==-1)cout << -1 << '\n';
  else {
    if(f)x.F=(x.F+1ll*n*x.S)%m;
    cout << x.F << ' ' << x.S << '\n';
  }

  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int n, m, a[100005];
set<int>st;
bool f = false;
int fast(int b, int e){
  int ret = 1;
  for(;e;e>>=1,b=1ll*b*b%m)
    if(e&1)
      ret=1ll*b*ret%m;
  return ret;
}
int getCnt(int d){
  int cnt = 0;
  f(i,0,n){
    cnt += st.count((a[i]+d)%m);
    cnt += st.count((a[i]+m-d)%m);
  }
  return cnt / 2;
}
int getFirst(int diff){
  int cnt = 0;
  int start = 0;
  f(i,0,n){
    if(st.count((a[i]+m-diff)%m))cnt++;
    else start = a[i];
  }
  if(cnt == n - 1)
    return start;
  return -1;
}
ii solve(){

  sort(a,a+n);

  int diff = a[1] - a[0];
  int cnt = n-getCnt(diff);
  int d = 1ll*diff*fast(cnt,m-2)%m;
//  cout<<diff<<' '<<d<<' '<<cnt<<'\n';
  auto x = getFirst(d);
  return make_pair(x,d);
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> m >> n;

  f(i,0,n){
    cin >> a[i];
    st.insert(a[i]);
  }

  if(2 * n > m){
    f = true;
    n = 0;
    f(i,0,m)
    if(st.count(i))st.erase(i);
    else {
      a[n++] = i;
      st.insert(i);
    }
  }

  if(!n){
    cout << "0 1\n";
    return 0;
  } else if(n == 1){
    if(!f)cout << a[0] << ' ' << 1 << '\n';
    else cout << (a[0] + 1) % m << ' ' << 1 << '\n';
    return 0;
  }

  auto x = solve();

  if(x.F==-1)cout << -1 << '\n';
  else {
    if(f)x.F=(x.F+1ll*n*x.S)%m;
    cout << x.F << ' ' << x.S << '\n';
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k = inv(ll(n) * (n - 1), m);
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k % m;
            if (((((n * x % m) * x) % m + (((x * n) % m) * (((n - 1) * d) % m)) % m) % m + (((d * d) % m) * ((ll)n * (n - 1) * (2 * n - 1) / 6) % m)) % m == ss)
            {
                printf("%lld %lld\n", x, d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k1 = inv(ll(n) * (n - 1), m), k2 = inv(6, m);
        ll k3 = ((ll(n) * (n - 1)) % m) % m;
        ll k4 = ((((ll(n) * (n - 1)) % m) * (2 * n - 1) % m) * k2) % m;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k1 % m;
            if ((((n * (x * x) % m) % m + ((x * d) % m) * k3) % m + (((d * d) % m) * k4) % m) % m == ss)
            {
                printf("%lld %lld\n", x, d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int m, n;
bool check(ll x, ll d)
{
    set<ll> s;
    for (int i = 0; i < n; i++)
        s.insert(a[i]);
    ll k = x;
    for (int i = 1; i < n; i++)
    {
        if (!s.count(k)) return false;
        k = (k + d) % m;
    }
    return true;
}
int main()
{
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s = (s + a[i]) % m;
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k1 = inv(ll(n) * (n - 1), m), k2 = inv(6, m);
        ll k3 = ((ll(n) * (n - 1)) % m) % m;
        ll k4 = ((((ll(n) * (n - 1)) % m) * (2 * n - 1) % m) * k2) % m;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k1 % m;
            if ((((n * ((x * x) % m)) % m + ((x * d) % m) * k3) % m + (((d * d) % m) * k4) % m) % m == ss)
            {
                if (check(x, d))
                {
                    printf("%lld %lld\n", x, d);
                    flag = false;
                    break;
                }
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k = inv(ll(n) * (n - 1), m), kk = inv(6, m);
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k % m;
            if (((((n * x % m) * x) % m + (((x * n) % m) * (((n - 1) * d) % m)) % m) % m + (((d * d) % m) * ((((ll)n * (n - 1)) % m) * (2 * n - 1) % m) * kk % m)) % m == ss)
            {
                printf("%lld %lld\n", x, d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k1 = inv(ll(n) * (n - 1), m), k2 = inv(6, m);
        ll k3 = ((ll(n) * (n - 1)) % m) % m;
        ll k4 = ((((ll(n) * (n - 1)) % m) * (2 * n - 1) % m) * k2) % m;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k1 % m;
            if ((((n * ((x * x) % m)) % m + ((x * d) % m) * k3) % m + (((d * d) % m) * k4) % m) % m == ss)
            {
                printf("%lld %lld\n", x, d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int m, n;
bool check(ll x, ll d)
{
    set<ll> s;
    for (int i = 0; i < n; i++)
        s.insert(a[i]);
    ll k = x;
    for (int i = 1; i < n; i++)
    {
        if (!s.count(k)) return false;
        k = (k + d) % m;
    }
    return true;
}
int main()
{
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s = (s + a[i]) % m;
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k3 = (ll(n) * (n - 1)) % m;
        ll k1 = inv(k3, m), k2 = inv(6 % m, m);
        ll k4 = ((((ll(n) * (n - 1)) % m) * (2 * n - 1) % m) * k2) % m;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s - ll(n) * x % m + m) % m) % m) * k1 % m;
            if (d == 0 && s == n * x % m)
            {
                if (check(x, 1))
                {
                    printf("%lld 1\n", x);
                    flag = false;
                    break;
                }
            }
            if ((((n * ((x * x) % m)) % m + ((x * d) % m) * k3) % m + (((d * d) % m) * k4) % m) % m == ss)
            {
                if (check(x, d))
                {
                    printf("%lld %lld\n", x, d);
                    flag = false;
                    break;
                }
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k = inv(ll(n) * (n - 1), m);
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k % m;
            if ((((n * x % m) * x % m + (x * n % m) * ((n - 1) * d % m) % m) % m + ((d * d % m) * (n * (n - 1) * (2 * n - 1) / 6) % m)) % m == ss)
            {
                printf("%lld %lld\n", x, d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int m, n;
bool check(ll x, ll d)
{
    set<ll> s;
    for (int i = 0; i < n; i++)
        s.insert(a[i]);
    ll k = x;
    for (int i = 1; i < n; i++)
    {
        if (!s.count(k)) return false;
        k = (k + d) % m;
    }
    return true;
}
int main()
{
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s = (s + a[i]) % m;
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k3 = (ll(n) * (n - 1)) % m;
        ll k1 = inv(k3, m), k2 = inv(6 % m, m);
        ll k4 = ((((ll(n) * (n - 1)) % m) * (2 * n - 1) % m) * k2) % m;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s - ll(n) * x % m + m) % m) % m) * k1 % m;
            if (d == 0 && s == n * x % m)
            {
                if (check(x, 1))
                {
                    printf("%lld %lld\n", x, 1);
                    flag = false;
                    break;
                }
            }
            if ((((n * ((x * x) % m)) % m + ((x * d) % m) * k3) % m + (((d * d) % m) * k4) % m) % m == ss)
            {
                if (check(x, d))
                {
                    printf("%lld %lld\n", x, d);
                    flag = false;
                    break;
                }
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef __int128 ll;
ll mod_pow(ll a, ll n, ll p) {
    a %= p;
    ll r = 1;
    while (n) {
        if (n & 1) r = r * a % p;
        a = a * a % p;
        n >>= 1;
    } return r;
}
ll inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
ll a[N];
int main()
{
    int m, n;
    while (~scanf("%d%d", &m, &n))
    {
        ll s = 0, ss = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s += a[i];
            ss = (ss + a[i] * a[i] % m) % m;
        }
        ll k = inv(ll(n) * (n - 1), m);
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            ll x = a[i];
            ll d = (2LL * ((s % m - ll(n) * x % m + m) % m) % m) * k % m;
            if (((((n * x % m) * x) % m + (((x * n) % m) * (((n - 1) * d) % m)) % m) % m + (((d * d) % m) * ((ll)n * (n - 1) * (2 * n - 1) / 6) % m)) % m == ss)
            {
                printf("%lld %lld\n", (long long)x, (long long)d);
                flag = false;
                break;
            }
        }
        if (flag) printf("-1\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i];
	sort(a,a+n);sum%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum,sum2;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
ll get(ll fir){
	ll res=0;
	res=fir*fir%p*n%p+1ll*(n-1)*n*(2*n-1)/6%p*D%p*D%p+1ll*(n-1)*n%p*D%p*fir%p;
	return res%p;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i],sum2+=1ll*a[i]*a[i]%p;
	sort(a,a+n);sum%=p;sum2%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]},num[cnt]++;
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
	//	cout<<num[cnt]<<' '<<num[0]<<"cnt\n";
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)&&get(a[i])==sum2){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i];
	sort(a,a+n);sum%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)){
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else{
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum,sum2;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
ll get(ll fir){
	ll res=0;
	res=fir*fir%p*n+(n-1)*n*(2*n-1)/6%p*D%p*D%p+(n-1)*n%p*D%p;
	return res%p;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i],sum2+=a[i]*a[i]%p;
	sort(a,a+n);sum%=p;sum2%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)&&get(a[i])==sum2){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i];
	sort(a,a+n);sum%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)){
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum,sum2;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
ll get(ll fir){
	ll res=0;
	res=fir*fir%p*n%p+(n-1)*n*(2*n-1)/6%p*D%p*D%p+(n-1)*n%p*D%p*fir%p;
	return res%p;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i],sum2+=a[i]*a[i]%p;
	sort(a,a+n);sum%=p;sum2%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)&&get(a[i])==sum2){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i];
	sort(a,a+n);sum%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>100){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum,sum2;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
ll get(ll fir){
	ll res=0;
	res=fir*fir%p*n%p+1ll*(n-1)*n*(2*n-1)/6%p*D%p*D%p+1ll*(n-1)*n%p*D%p*fir%p;
	return res%p;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i],sum2+=1ll*a[i]*a[i]%p;
	sort(a,a+n);sum%=p;sum2%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)&&get(a[i])==sum2){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N],f[N],cnt,num[N],p,n;
ll D,sum,sum2;
pii d[N];
bool find(int x){
	int l=0,r=cnt;
	while(l<r){
		int mid=l+r>>1;
		if(d[mid].fi<x)l=mid+1;
		else r=mid;
	}
	D=d[l].se;
	return x==d[l].fi;
}
ll get(ll fir){
	ll res=0;
	res=fir*fir%p*n%p+(n-1)*n*(2*n-1)/6%p*D%p*D%p+(n-1)*n%p*D%p*fir%p;
	return res%p;
}
int main(){
	scanf("%d%d",&p,&n);
	rep(i,0,n)scanf("%d",&a[i]),sum+=a[i],sum2+=1ll*a[i]*a[i]%p;
	sort(a,a+n);sum%=p;sum2%=p;
	ll m=1ll*n*(n-1)/2%p;
	num[0]=1;
	rep(i,1,n){
		if(a[i]!=a[i-1])d[cnt++]={(sum-(a[i]-a[0])*m%p+p)%p,a[i]-a[0]};
		else num[cnt]++;
	}
	sort(num,num+cnt+1);
	sort(d,d+cnt);
//	rep(i,0,cnt)cout<<d[i].fi<<" ";
//	cout<<"D\n";
	if(cnt==0){
		printf("%d %d",a[0],0);
		return 0;
	}
	if(n<=p){
		if(num[cnt]>=2){
			printf("-1");
			return 0;
		}
	}
	else{
		if(num[cnt]-num[0]>1){
			printf("-1");
			return 0;
		}
	}
	if(n%p==0){
		if(num[cnt]!=num[0]||cnt!=p-1){
			printf("-1");
		}
		else printf("%d %d",a[0],1);
		return 0;
	}
	int cnt2=0;
	per(i,0,n){
		if(a[i]==a[i+1])continue;
		int born=1ll*a[i]*n%p;
		if(find(born)&&get(a[i])==sum2){
			cnt2++;
//		cout<<a[i]<<' '<<D<<"born\n";
			rep(j,0,n)b[j]=(a[i]+j*D)%p;
		//	cout<<"bbb\n";
			sort(b,b+n);
			int flag=1;
			rep(j,0,n)if(a[j]!=b[j]){
			//	cout<<a[j]<<' '<<b[j]<<"which\n";
				flag=0;
				break;
			}
			if(flag){
				printf("%d %lld",a[i],D);
				return 0;
			}
			else if(cnt2>350){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll m, a[MAXN], inv[MAXN];
set<int> all;

bool check(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(!all.count((x + i * d) % m))
            return false;
    }
    return true;
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all.insert(a[i]);
    }
    inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = m - (m / i) * inv[m % i] % m;
    if(n == m) {
        cout << "0 1\n";
        return 0;
    }
    if(n == 1) {
        cout << a[0] << " " << 0 << '\n';
        return 0;
    }
    if(n == 2) {
        cout << min(a[0], a[1]) << " " << max(a[0], a[1]) - min(a[0], a[1]) << '\n';
        return 0;
    }
    ll s = 0, ss = 0;
    for(int i = 0; i < n; i++) {
        s = (s + a[i]) % m;
        ss = (ss + a[i] * a[i]) % m;
    }
    ll inn = (inv[n] * inv[n - 1]) % m;
    ll lit = ((ll)n * (n - 1)) % m;
    ll sqt = (lit * (2*n - 1)) % m;
    sqt = (sqt * inv[6]) % m;
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        ll d = 2*s;
        d = (d * inn) % m;
        ll ex = (inv[n - 1] * 2) % m;
        ex = (ex * x) % m;
        d = (d - ex) % m;
        d = (d + m) % m;
        ll su = (n * (x * x) % m + lit * (d * x) % m + sqt * (d * d) % m) % m;
        if(su != ss)
            continue;
        if(check(x, d)) {
            cout << x << " " << d << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll m, a[MAXN], inv[MAXN];
set<int> all;

bool check(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(!all.count((x + i * d) % m))
            return false;
    }
    return true;
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all.insert(a[i]);
    }
    inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = m - (m / i) * inv[m % i] % m;
    if(n == m) {
        cout << "0 1\n";
        return 0;
    }
    if(n == 1) {
        cout << a[0] << " " << 0 << '\n';
        return 0;
    }
    if(n == 2) {
        cout << min(a[0], a[1]) << " " << max(a[0], a[1]) - min(a[0], a[1]) << '\n';
        return 0;
    }
    ll s = 0, ss = 0;
    for(int i = 0; i < n; i++) {
        s = (s + a[i]) % m;
        ss = (ss + a[i] * a[i]) % m;
    }
    ll inn = (inv[n] * inv[n - 1]) % m;
    ll lit = ((ll)n * (n - 1)) % m;
    ll sqt = (lit * (2*n - 1)) % m;
    sqt = (sqt * inv[6]) % m;
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        ll d = 2*s;
        d = (d * inn) % m;
        ll ex = (inv[n - 1] * 2) % m;
        ex = (ex * x) % m;
        d = (d - ex) % m;
        d = (d + m) % m;
        ll su = ((n * (x * x % m))%m + (lit * (d * x % m))%m + (sqt * (d * d % m)%m)) % m;
        if(su != ss)
            continue;
        if(check(x, d)) {
            cout << x << " " << d << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll m, a[MAXN], inv[MAXN];
set<int> all;

bool check(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(!all.count((x + i * d) % m))
            return false;
    }
    return true;
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all.insert(a[i]);
    }
    inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = m - (m / i) * inv[m % i] % m;
    if(n == m) {
        cout << "0 1\n";
        return 0;
    }
    if(n == 1) {
        cout << a[0] << " " << 0 << '\n';
        return 0;
    }
    if(n == 2) {
        cout << min(a[0], a[1]) << " " << max(a[0], a[1]) - min(a[0], a[1]) << '\n';
        return 0;
    }
    ll s = 0, ss = 0;
    for(int i = 0; i < n; i++) {
        s = (s + a[i]) % m;
        ss = (ss + a[i] * a[i]) % m;
    }
    ll inn = (inv[n] * inv[n - 1]) % m;
    ll lit = (n * (n - 1)) % m;
    ll sqt = (lit * (2*n - 1)) % m;
    sqt = (sqt * inv[6]) % m;
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        ll d = 2*s;
        d = (d * inn) % m;
        ll ex = (inv[n - 1] * 2) % m;
        ex = (ex * x) % m;
        d = (d - ex) % m;
        d = (d + m) % m;
        ll su = (n * (x * x) % m + lit * (d * x) % m + sqt * (d * d) % m) % m;
        if(su != ss)
            continue;
        if(check(x, d)) {
            cout << x << " " << d << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll m, a[MAXN], inv[MAXN];
set<int> all;

bool check(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(!all.count((x + i * d) % m))
            return false;
    }
    return true;
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all.insert(a[i]);
    }
    inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = m - (m / i) * inv[m % i] % m;
    if(n == m) {
        cout << "0 1\n";
        return 0;
    }
    if(n == 1) {
        cout << a[0] << " " << 0 << '\n';
        return 0;
    }
    if(n == 2) {
        cout << min(a[0], a[1]) << " " << max(a[0], a[1]) - min(a[0], a[1]) << '\n';
        return 0;
    }
    ll s = 0, ss = 0;
    for(int i = 0; i < n; i++) {
        s = (s + a[i]) % m;
        ss = (ss + a[i] * a[i]) % m;
    }
    ll inn = (inv[n] * inv[n - 1]) % m;
    ll lit = ((ll)n * (n - 1)) % m;
    ll sqt = (lit * (2*n - 1)) % m;
    sqt = (sqt * inv[6]) % m;
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        ll d = 2*s;
        d = (d * inn) % m;
        ll ex = (inv[n - 1] * 2) % m;
        ex = (ex * x) % m;
        d = (d - ex) % m;
        d = (d + m) % m;
        ll su = ((n * (x * x) % m)%m + (lit * (d * x) % m)%m + (sqt * (d * d) % m)%m) % m;
        if(su != ss)
            continue;
        if(check(x, d)) {
            cout << x << " " << d << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll m, a[MAXN], inv[MAXN];
set<int> all;

bool check(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(!all.count((x +(ll) i * d) % m))
            return false;
    }
    return true;
}

int main() {
    cin >> m >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all.insert(a[i]);
    }
    inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = m - (m / i) * inv[m % i] % m;
    if(n == m) {
        cout << "0 1\n";
        return 0;
    }
    if(n == 1) {
        cout << a[0] << " " << 0 << '\n';
        return 0;
    }
    if(n == 2) {
        cout << min(a[0], a[1]) << " " << max(a[0], a[1]) - min(a[0], a[1]) << '\n';
        return 0;
    }
    ll s = 0, ss = 0;
    for(int i = 0; i < n; i++) {
        s = (s + a[i]) % m;
        ss = (ss + a[i] * a[i]) % m;
    }
    ll inn = (inv[n] * inv[n - 1]) % m;
    ll lit = ((ll)n * (n - 1)) % m;
    ll sqt = (lit * (2*n - 1)) % m;
    sqt = (sqt * inv[6]) % m;
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        ll d = 2*s;
        d = (d * inn) % m;
        ll ex = (inv[n - 1] * 2) % m;
        ex = (ex * x) % m;
        d = (d - ex) % m;
        d = (d + m) % m;
        ll su = ((n * (x * x % m))%m + (lit * (d * x % m))%m + (sqt * (d * d % m)%m)) % m;
        if(su != ss)
            continue;
        if(check(x, d)) {
            cout << x << " " << d << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
int P;
int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 1e5 + 7;
int n, s1, s2, a[N], b[N];
unordered_map<int, int> M;

int inv(int x) {return kpow(x, P - 2);}

void solve(int d) {
	int a1 = mul(sub(s1, mul(1ll * n * (n - 1) / 2 % P, d)), inv(n));
	if (!M.count(a1)) return;
	int tmp = mul(n, mul(a1, a1));
	int x = 1ll * n * (n - 1) % P * add(mul(a1, d), mul(mul(2 * n - 1, mul(d, d)), inv(6))) % P;
	tmp = add(tmp, x);
	//if (d == 2) dd(tmp), de(s2);
	if (tmp != s2) return;
	b[1] = a1;
	rep(i, 2, n+1) b[i] = add(b[i-1], d);
	sort(b + 1, b + n + 1);
	rep(i, 1, n+1) if (b[i] != a[i]) return;
	cout << a1 << " " << d;
	exit(0);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> P >> n;
	rep(i, 1, n+1) cin >> a[i], s1 = add(s1, a[i]), s2 = add(s2, mul(a[i], a[i])), M[a[i]] = 1;
	sort(a + 1, a + n + 1);
	if (n == 1) {
		cout << a[1] << " " << 0;
		return 0;
	}
	rep(i, 2, n+1) {
		solve(sub(a[i], a[1]));
		solve(sub(a[1], a[i]));
	}
	cout << -1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
int P;
int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 1e5 + 7;
int n, s1, s2, a[N], b[N];
unordered_map<int, int> M;

int inv(int x) {return kpow(x, P - 2);}

void solve(int d) {
	int a1 = mul(sub(s1, mul(1ll * n * (n - 1) / 2 % P, d)), inv(n));
	if (!M.count(a1)) return;
	int tmp = mul(n, mul(a1, a1));
	int x = 1ll * n * (n - 1) % P * add(mul(a1, d), mul(mul(2 * n - 1, mul(d, d)), inv(6))) % P;
	tmp = add(tmp, x);
	//if (d == 2) dd(tmp), de(s2);
	if (tmp != s2) return;
	b[1] = a1;
	rep(i, 2, n+1) b[i] = add(b[i-1], d);
	sort(b + 1, b + n + 1);
	rep(i, 1, n+1) if (b[i] != a[i]) return;
	cout << a1 << " " << d;
	exit(0);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> P >> n;
	rep(i, 1, n+1) cin >> a[i], s1 = add(s1, a[i]), s2 = add(s2, mul(a[i], a[i])), M[a[i]] = 1;
	sort(a + 1, a + n + 1);
	rep(i, 2, n+1) {
		solve(sub(a[i], a[1]));
		solve(sub(a[1], a[i]));
	}
	cout << -1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>

template <typename T>
void resize(int n, vector<T> &u) {
  u.resize(n);
}

template <typename Head, typename... Tail>
void resize(int n, Head &H, Tail&... T) {
  resize(n, H);
  resize(n, T...);
}

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> &u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}

vector<char> lowchar = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> hichar = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char> base_10 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

template <typename T>
string to_string(T t) {
  ostringstream ss;
  ss << t;
  return ss.str();
}

long long to_num(string t) {
  long long res = 0;
  for(int i = 0; i < (int) t.length(); i++) {
    res *= 10;
    res += t[i] - '0';
  }
  return res;
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, m;

inline void add(int &a, int b) {
  a += b;
  if (a >= m) a -= m;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += m;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % m);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, md;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (md)
    : "d" (xh), "a" (xl), "r" (m)
  );
  return md;
}

inline int inv(int a) {
  a %= m;
  if (a < 0) a += m;
  int b = m, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += m;
  return u;
}

pair<int, int> solve(vector<int> a) {
  int cur = 0;
  range(i, 0, n) {
    add(cur, a[i]);
  }
  set<int> b;
  range(i, 0, n) b.insert(a[i]);
  cur = mul(cur, inv(n));
  cur = mul(2, cur);
  range(rot, 0, 2) {
    if(mul(a[rot], 2) == cur) continue;
    int v = mul(a[rot], 2);
    int cnt = 0;
    range(i, 0, n) {
      int t = v;
      sub(t, a[i]);
      if(b.find(t) != b.end()) cnt++;
    }
    if(cnt % 2 == 0) {
      return make_pair(-1, -1);
    }
    int pos = (cnt - 1);
    if(pos == n - 1) {
      return make_pair(-1, -1);
    }
    int x = cur;
    sub(x, v);
    int y = n - 1;
    sub(y, pos);
    int d = mul(x, inv(y));
    int z = cur;
    sub(z, mul(n - 1, d));
    z = mul(z, inv(2));
    return make_pair(z, d);
  }
}

bool check(int x, int d, vector<int> a) {
  vector<int> b(n);
  range(i, 0, n) {
    b[i] = x;
    add(b[i], mul(i, d));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  return a == b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  vector<int> a(n);
  range(i, 0, n) cin >> a[i];
  if(n == 1) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(m == 2) {
    if(a[0] == a[1]) cout << a[0] << " " << 0;
    else cout << a[0] << " " << 1;
    return 0;
  }
  if(*max_element(a.begin(), a.end()) == *min_element(a.begin(), a.end())) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(n == m) {
    cout << 0 << " " << 1;
    return 0;
  }
  if(2 * n < m) {
    pair<int, int> res = solve(a);
    int x = res.first, d = res.second;
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(check(x, d, a)) {
      cout << x << " " << d;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  } else {
    vector<int> b;
    set<int> c;
    for(auto i : a) c.insert(i);
    range(i, 0, m) if(c.find(i) == c.end()) b.push_back(i);
    n = b.size();
    pair<int, int> res = solve(b);
    int x = res.first, d = res.second;
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(!check(x, d, b)) {
      cout << -1;
      return 0;
    } else {
      add(x, mul(n, d));
      cout << x << " " << d;
      return 0;
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>

template <typename T>
void resize(int n, vector<T> &u) {
  u.resize(n);
}

template <typename Head, typename... Tail>
void resize(int n, Head &H, Tail&... T) {
  resize(n, H);
  resize(n, T...);
}

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> &u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}

vector<char> lowchar = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> hichar = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char> base_10 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

template <typename T>
string to_string(T t) {
  ostringstream ss;
  ss << t;
  return ss.str();
}

long long to_num(string t) {
  long long res = 0;
  for(int i = 0; i < (int) t.length(); i++) {
    res *= 10;
    res += t[i] - '0';
  }
  return res;
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, m;

inline void add(int &a, int b) {
  a += b;
  if (a >= m) a -= m;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += m;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % m);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, md;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (md)
    : "d" (xh), "a" (xl), "r" (m)
  );
  return md;
}

inline int inv(int a) {
  a %= m;
  if (a < 0) a += m;
  int b = m, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += m;
  return u;
}

pair<int, int> solve(vector<int> a) {
  int cur = 0;
  range(i, 0, n) {
    add(cur, a[i]);
  }
  set<int> b;
  range(i, 0, n) b.insert(a[i]);
  cur = mul(cur, inv(n));
  cur = mul(2, cur);
  range(rot, 0, 2) {
    if(mul(a[rot], 2) == cur) continue;
    int v = mul(a[rot], 2);
    int cnt = 0;
    range(i, 0, n) {
      int t = v;
      sub(t, a[i]);
      if(b.find(t) != b.end()) cnt++;
    }
    if(cnt % 2 == 0) {
      return make_pair(-1, -1);
    }
    int pos = (cnt - 1);
    if(pos == n - 1) {
      return make_pair(-1, -1);
    }
    int x = cur;
    sub(x, v);
    int y = n - 1;
    sub(y, pos);
    int d = mul(x, inv(y));
    int z = cur;
    sub(z, mul(n - 1, d));
    z = mul(z, inv(2));
    return make_pair(z, d);
  }
}

bool check(int x, int d, vector<int> a) {
  vector<int> b(n);
  range(i, 0, n) {
    b[i] = x;
    add(b[i], mul(i, d));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  return a == b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  vector<int> a(n);
  range(i, 0, n) cin >> a[i];
  if(n == 1) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(m == 2) {
    if(a[0] == a[1]) cout << a[0] << " " << 0;
    else cout << a[0] << " " << 1;
    return 0;
  }
  if(*max_element(a.begin(), a.end()) == *min_element(a.begin(), a.end())) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(n == m) {
    cout << 0 << " " << 1;
    return 0;
  }
  if(n == m - 1) {
    set<int> b;
    range(i, 0, n) b.insert(a[i]);
    range(i, 0, m) {
      if(b.find(i) == b.end()) {
        cout << ((i + 1) % m) << " " << 1;
        return 0;
      }
    }
  }
  if(2 * n < m) {
    pair<int, int> res = solve(a);
    int x = res.first, d = res.second;
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(check(x, d, a)) {
      cout << x << " " << d;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  } else {
    vector<int> b;
    set<int> c;
    for(auto i : a) c.insert(i);
    range(i, 0, m) if(c.find(i) == c.end()) b.push_back(i);
    n = b.size();
    pair<int, int> res = solve(b);
    int x = res.first, d = res.second;
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(!check(x, d, b)) {
      cout << -1;
      return 0;
    } else {
      add(x, mul(n, d));
      cout << x << " " << d;
      return 0;
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>

template <typename T>
void resize(int n, vector<T> &u) {
  u.resize(n);
}

template <typename Head, typename... Tail>
void resize(int n, Head &H, Tail&... T) {
  resize(n, H);
  resize(n, T...);
}

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> &u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> &t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}

vector<char> lowchar = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> hichar = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char> base_10 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

template <typename T>
string to_string(T t) {
  ostringstream ss;
  ss << t;
  return ss.str();
}

long long to_num(string t) {
  long long res = 0;
  for(int i = 0; i < (int) t.length(); i++) {
    res *= 10;
    res += t[i] - '0';
  }
  return res;
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, m;

inline void add(int &a, int b) {
  a += b;
  if (a >= m) a -= m;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += m;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % m);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, md;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (md)
    : "d" (xh), "a" (xl), "r" (m)
  );
  return md;
}

inline int inv(int a) {
  a %= m;
  if (a < 0) a += m;
  int b = m, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += m;
  return u;
}

pair<int, int> solve(vector<int> a) {
  int cur = 0;
  range(i, 0, n) {
    add(cur, a[i]);
  }
  set<int> b;
  range(i, 0, n) b.insert(a[i]);
  cur = mul(cur, inv(n));
  cur = mul(2, cur);
  range(rot, 0, 2) {
    if(mul(a[rot], 2) == cur) continue;
    int v = mul(a[rot], 2);
    int cnt = 0;
    range(i, 0, n) {
      int t = v;
      sub(t, a[i]);
      if(b.find(t) != b.end()) cnt++;
    }
    if(cnt % 2 == 0) {
      return make_pair(-1, -1);
    }
    int pos = (cnt - 1);
    if(pos == n - 1) {
      return make_pair(-1, -1);
    }
    int x = cur;
    sub(x, v);
    int y = n - 1;
    sub(y, pos);
    int d = mul(x, inv(y));
    int z = cur;
    sub(z, mul(n - 1, d));
    z = mul(z, inv(2));
    return make_pair(z, d);
  }
}

bool check(int x, int d, vector<int> a) {
  vector<int> b(n);
  range(i, 0, n) {
    b[i] = x;
    add(b[i], mul(i, d));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  return a == b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  vector<int> a(n);
  range(i, 0, n) cin >> a[i];
  if(n == 1) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(m == 2) {
    if(a[0] == a[1]) cout << a[0] << " " << 0;
    else cout << a[0] << " " << 1;
    return 0;
  }
  if(*max_element(a.begin(), a.end()) == *min_element(a.begin(), a.end())) {
    cout << a[0] << " " << 0;
    return 0;
  }
  if(2 * n < m) {
    pair<int, int> res = solve(a);
    int x = res.first, d = res.second;
    debug(res);
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(check(x, d, a)) {
      cout << x << " " << d;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  } else {
    vector<int> b;
    set<int> c;
    for(auto i : a) c.insert(i);
    range(i, 0, m) if(c.find(i) == c.end()) b.push_back(i);
    n = b.size();
    pair<int, int> res = solve(b);
    int x = res.first, d = res.second;
    if(x == -1) {
      cout << -1;
      return 0;
    }
    if(!check(x, d, b)) {
      cout << -1;
      return 0;
    } else {
      add(x, mul(n, d));
      cout << x << " " << d;
      return 0;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;

int m,n,a[MAXN],d[MAXN],x,pt,cnt;
set <int> s;

inline int check(int d)
{
	multiset <int> ms;
	for (int i=1;i<=n;i++) ms.insert(a[i]);
	int x=a[1];int las;
	for (;;(x+=d)%=m)
	{
		if (ms.find(x)==ms.end()) break;
		las=x;
		ms.erase(x);
	}
	x=(a[1]-d+m)%m;
	for (;;x=(x-d+m)%m)
	{
		if (ms.find(x)==ms.end()) break;
		las=x;
		ms.erase(x);
	}
	if (ms.size()) return -1;
	return las;
}

int main()
{
	scanf("%d %d",&m,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (n==1) return printf("%d %d\n",a[1],m-1),0;
	sort(a+1,a+n+1);
	for (int i=2;i<=n;i++) d[i]=a[i]-a[i-1],s.insert(d[i]);
	if (s.size()>2) return puts("-10"),0;
	if (s.size()==1) return printf("%d %d\n",a[1],d[2]),0;
	int x=check(*s.begin());
	if (x!=-1) return printf("%d %d\n",x,*s.begin()),0;
	s.erase(s.begin());
	x=check(*s.begin());
	if (x!=-1) return printf("%d %d\n",x,*s.begin()),0;
	puts("-1");
	return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;

int m,n,a[MAXN],d[MAXN],x,pt,cnt;
set <int> s;

inline int check(int d)
{
	multiset <int> ms;
	for (int i=1;i<=n;i++) ms.insert(a[i]);
	int x=a[1];int las;
	for (;;(x+=d)%=m)
	{
		if (ms.find(x)==ms.end()) break;
		las=x;
		ms.erase(x);
	}
	x=(a[1]-d+m)%m;
	for (;;x=(x-d+m)%m)
	{
		if (ms.find(x)==ms.end()) break;
		las=x;
		ms.erase(x);
	}
	if (ms.size()) return -1;
	return las;
}

int main()
{
	scanf("%d %d",&m,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (n==1) return printf("%d %d\n",a[1],m-1),0;
	sort(a+1,a+n+1);
	for (int i=2;i<=n;i++) d[i]=a[i]-a[i-1],s.insert(d[i]);
	if (s.size()>2) return puts("-10"),0;
	if (s.size()==1) return printf("%d %d\n",a[1],d[2]),0;
	int x=check(*s.begin());
	if (x!=-1) return printf("%d %d\n",x,*s.begin());
	s.erase(s.begin());
	x=check(*s.begin());
	if (x!=-1) return printf("%d %d\n",x,*s.begin());
	puts("-1");
	return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;

int m,n,a[MAXN],d,x=-1;
set <int> s;

inline long long fpow(long long a,long long b)
{
	long long r=1;
	for (;b;b>>=1,(a*=a)%=m) if (b&1) (r*=a)%=m;
	return r;
}

inline int getK(int d)
{
	int k=0;
	for (int i=1;i<=n;i++)
		for (int j=-d;j<=d;j+=d+d)
		{
			int y=(a[i]+j+m)%m;
			if (a[i]<=y&&s.find(y)!=s.end()) ++k;
		}
	return k;
}

inline void solve()
{
	if (n<=1)
	{
		x=!n?1:a[1];d=1;
		return ;
	}
	int k=n-getK(a[2]-a[1]);
	d=1LL*fpow(k,m-2)*(a[2]-a[1])%m;
	int y=a[1],cnt=0;
	while (true)
	{
		if (s.find(y)==s.end()) break;
		y+=d;if (y>=m) y-=m;++cnt;
	}
	y=a[1];
	while (true)
	{
		if (s.find(y)==s.end()) break;
		x=y;y-=d;if (y<0) y+=m;++cnt;
	}
	if (cnt!=n+1){x=-1;d=-1;}
	return ;
}

int main()
{
	scanf("%d %d",&m,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),s.insert(a[i]);
	if (n==1) return printf("%d %d\n",a[1],m-1),0;
	sort(a+1,a+n+1);
	if (m<=(n<<1))
	{
		for (int i=0;i<m;i++)
			if (s.find(i)==s.end())
				a[++a[0]]=i;
		n=m-n;s.clear();
		for (int i=1;i<=n;i++) s.insert(a[i]);
		solve();
		if (~x) (x+=1LL*n*d%m)%=m;
	}
	else solve();
	if (~x) return printf("%d %d\n",x,d),0;
	puts("-1");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

typedef long long ll;

int a[maxn],m,n;

int pow(int a,int b)
{
	int tmp = 1;
	for(;b;b >>= 1,a = a * 1ll * a % m)
		if (b & 1) tmp = tmp * 1ll * a % m;
	return tmp;
}

int main()
{
	scanf("%d%d", &m, &n);
	ll s = 0,s1 = 0,qs = 0;
	for(int i = 0;i < n;i ++)
	{
		scanf("%d", &a[i]);
		s += a[i],s1 = (s1 + a[i] * 1ll * a[i]) % m;
		qs += i * 1ll * i;
	}
	s %= m,s1 %= m,qs %= m;
	sort(a,a + n);
	for(int i = 0;i < n;i ++)
	{
		int d = a[i] - a[0];
		int x = ((s - n * (n - 1ll) / 2 % m * d % m) % m * pow(n,m - 2) % m + m) % m;
		if ((((x * 1ll * x) % m * n % m + n * (n - 1ll) % m * d % m * x % m + d * 1ll * d % m * qs % m) % m + m) % m == s1)
		{
			int b[maxn];
			for(int j = 0;j < n;j ++) b[j] = (x + d * 1ll * j) % m;
			sort(b,b + n);
			bool ok = 1;
			for(int j = 0;j < n;j ++)
				if (b[j] != a[j]) {ok = 0;break;}
			if (ok)
			{
				printf("%d %d\n", x,  d);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
typedef long long ll;
int a[maxn],m,n;

int pow(int a,int b)
{
	int tmp = 1;
	for(;b;b >>= 1,a = a * 1ll * a % m)
		if (b & 1) tmp = tmp * 1ll * a % m;
	return tmp;
}

int main()
{
	scanf("%d%d", &m, &n);
	ll s = 0,s1 = 0,qs = 0;
	for(int i = 0;i < n;i ++)
	{
		scanf("%d", &a[i]);
		s += a[i],s1 = (s1 + a[i] * 1ll * a[i]) % m;
		qs += i * 1ll * i;
	}
	s %= m,s1 %= m,qs %= m;
	sort(a,a + n);
	for(int i = 0;i < n;i ++)
	{
		int d = a[i] - a[0];
		int x = ((s - n * (n - 1ll) / 2 % m * d % m) % m * pow(n,m - 2) % m + m) % m;
		if ((((x * 1ll * x) % m * n % m + n * (n - 1ll) % m * d % m * x % m + d * 1ll * d % m * qs % m) % m + m) % m == s1)
		{
		    int b[maxn];
			for(int j = 0;j < n;j ++) b[j] = (x + d * 1ll * j) % m;
			sort(b,b + n);
			bool ok = 1;
			for(int j = 0;j < n;j ++)
				if (b[j] != a[j]) {ok = 0;break;}
			if (ok)
			{
				printf("%d %d\n", x,  d);
				return 0;
			}
		}
	}
	printf("1\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

typedef long long ll;

int a[maxn],m,n;

int pow(int a,int b)
{
	int tmp = 1;
	for(;b;b >>= 1,a = a * 1ll * a % m)
		if (b & 1) tmp = tmp * 1ll * a % m;
	return tmp;
}

int main()
{
	scanf("%d%d", &m, &n);
	ll s = 0,s1 = 0,qs = 0;
	for(int i = 0;i < n;i ++)
	{
		scanf("%d", &a[i]);
		s += a[i],s1 = (s1 + a[i] * 1ll * a[i]) % m;
		qs += i * 1ll * i;
	}
	s %= m,s1 %= m,qs %= m;
	sort(a,a + n);
	for(int i = 0;i < n;i ++)
	{
		int d = a[i] - a[1];
		int x = ((s - n * (n - 1ll) / 2 % m * d % m) % m * pow(n,m - 2) % m + m) % m;
		if ((((x * 1ll * x) % m * n % m + n * (n - 1ll) % m * d % m * x % m + d * 1ll * d % m * qs % m) % m + m) % m == s1)
		{
			int b[maxn];
			for(int j = 0;j < n;j ++) b[j] = (x + d * 1ll * j) % m;
			sort(b,b + n);
			bool ok = 1;
			for(int j = 0;j < n;j ++)
				if (b[j] != a[j]) {ok = 0;break;}
			if (ok)
			{
				printf("%d %d\n", x,  d);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

typedef long long ll;

int a[maxn],m,n;

int pow(int a,int b)
{
	int tmp = 1;
	for(;b;b >>= 1,a = a * 1ll * a % m)
		if (b & 1) tmp = tmp * 1ll * a % m;
	return tmp;
}

int main()
{
	scanf("%d%d", &m, &n);
	ll s = 0,s1 = 0,qs = 0;
	for(int i = 0;i < n;i ++)
	{
		scanf("%d", &a[i]);
		s += a[i],s1 = (s1 + a[i] * 1ll * a[i]) % m;
		qs += i * 1ll * i;
	}
	s %= m,s1 %= m,qs %= m;
	sort(a,a + n);
	for(int i = 0;i < n;i ++)
	{
		int d = a[i] - a[0];
		int x = ((s - n * (n - 1ll) / 2 % m * d % m) % m * pow(n,m - 2) % m + m) % m;
		if ((((x * 1ll * x) % m * n % m + n * (n - 1ll) % m * d % m * x % m + d * 1ll * d % m * qs % m) % m + m) % m == s1)
		{
			int b[maxn];
			for(int j = 0;j < n;j ++) b[j] = (x + d * 1ll * j) % m;
			sort(b,b + n);
			bool ok = 1;
			for(int j = 0;j < n;j ++)
				if (b[j] != a[j]) {ok = 0;break;}
			if (ok)
			{
				printf("%d %d\n", x,  d);
				return 1;
			}
		}
	}
	printf("-1\n");
	return 0;
}


/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/5/11
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, m;
int x, d;

// 1 2 3 4 5
// k = 3
// 1 4, 2 5 tmp = 2

void solve(const vector<int>& a) {
    if (a.size() == 1) {
        x = 0, d = a[0];
        return;
    }
    set<int> mp;
    for (auto i : a) mp.insert(i);
    int t = a[1] - a[0];
    int tmp = 0;
    for (auto i : a) {
        if (mp.count((i + t) % m)) tmp ++;
    }
    int k = a.size() - tmp;
    x = a[0];
    d = 1ll * t * qp(k, m - 2, m) % m;
    while (mp.count((x - d + m) % m)) x = (x - d + m) % m;
    for (int i = 0; i < a.size(); ++i) {
        if (!mp.count((x + 1ll * i * d) % m)) {
            x = -1;
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    scanf("%d%d", &m, &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    if (n * 2 < m) {
        solve(a);
    } else {
        vector<int> inva;
        int pos = 0;
        for (int i = 0; i < m; ++i) {
            if (pos < a.size() && a[pos] == i) pos ++;
            else inva.push_back(i);
        }
        solve(inva);
        if (x != -1) x = ((x - 1ll * n * d % m) % m + m) % m;
    }
    if (x == -1) printf("-1\n");
    else printf("%d %d\n", x, d);
    return 0;
}


/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/5/11
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, m;
int x, d;

// 1 2 3 4 5
// k = 3
// 1 4, 2 5 tmp = 2

void solve(const vector<int>& a) {
    if (a.size() == 1) {
        x = a[0], d = 0;
        return;
    }
    set<int> mp;
    for (auto i : a) mp.insert(i);
    int t = a[1] - a[0];
    int tmp = 0;
    for (auto i : a) {
        if (mp.count((i + t) % m)) tmp ++;
    }
    int k = a.size() - tmp;
    x = a[0];
    d = 1ll * t * qp(k, m - 2, m) % m;
    while (mp.count((x - d + m) % m)) x = (x - d + m) % m;
    for (int i = 0; i < a.size(); ++i) {
        if (!mp.count((x + 1ll * i * d) % m)) {
            x = -1;
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    scanf("%d%d", &m, &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    if (n == 1) {
        printf("%d %d\n", a[0], 0);
        return 0;
    } else if (n == m) {
        for (int i = 0; i < n; ++i) {
            if (a[i] != i) {
                printf("-1\n");
                return 0;
            }
        }
        printf("0 1");
        return 0;
    }
    if (n * 2 < m) {
        solve(a);
    } else {
        vector<int> inva;
        int pos = 0;
        for (int i = 0; i < m; ++i) {
            if (pos < a.size() && a[pos] == i) pos ++;
            else inva.push_back(i);
        }
        solve(inva);
        if (x != -1) x = ((x - 1ll * n * d % m) % m + m) % m;
    }
    if (x == -1) printf("-1\n");
    else printf("%d %d\n", x, d);
    return 0;
}


/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/5/11
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, m;
int x, d;

// 1 2 3 4 5
// k = 3
// 1 4, 2 5 tmp = 2

void solve(const vector<int>& a) {
    if (a.size() == 1) {
        x = a[0], d = 1;
        return;
    }
    set<int> mp;
    for (auto i : a) mp.insert(i);
    int t = a[1] - a[0];
    int tmp = 0;
    for (auto i : a) {
        if (mp.count((i + t) % m)) tmp ++;
    }
    int k = a.size() - tmp;
    x = a[0];
    d = 1ll * t * qp(k, m - 2, m) % m;
    while (mp.count((x - d + m) % m)) x = (x - d + m) % m;
    for (int i = 0; i < a.size(); ++i) {
        if (!mp.count((x + 1ll * i * d) % m)) {
            x = -1;
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    scanf("%d%d", &m, &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    if (n == 1) {
        printf("%d %d\n", a[0], 0);
        return 0;
    } else if (n == m) {
        for (int i = 0; i < n; ++i) {
            if (a[i] != i) {
                printf("-1\n");
                return 0;
            }
        }
        printf("0 1");
        return 0;
    }
    if (n * 2 < m) {
        solve(a);
    } else {
        vector<int> inva;
        int pos = 0;
        for (int i = 0; i < m; ++i) {
            if (pos < a.size() && a[pos] == i) pos ++;
            else inva.push_back(i);
        }
        solve(inva);
        if (x != -1) x = ((x - 1ll * n * d % m) % m + m) % m;
    }
    if (x == -1) printf("-1\n");
    else printf("%d %d\n", x, d);
    return 0;
}


/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/5/11
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, m;
int x, d;

// 1 2 3 4 5
// k = 3
// 1 4, 2 5 tmp = 2

void solve(const vector<int>& a) {
    if (a.size() == 1) {
        x = a[0], d = 0;
        return;
    }
    set<int> mp;
    for (auto i : a) mp.insert(i);
    int t = a[1] - a[0];
    int tmp = 0;
    for (auto i : a) {
        if (mp.count((i + t) % m)) tmp ++;
    }
    int k = a.size() - tmp;
    x = a[0];
    d = 1ll * t * qp(k, m - 2, m) % m;
    while (mp.count((x - d + m) % m)) x = (x - d + m) % m;
    for (int i = 0; i < a.size(); ++i) {
        if (!mp.count((x + 1ll * i * d) % m)) {
            x = -1;
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    scanf("%d%d", &m, &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    if (n == 1) {
        printf("%d %d\n", a[0], 0);
        return 0;
    }
    sort(a.begin(), a.end());
    if (n * 2 < m) {
        solve(a);
    } else {
        vector<int> inva;
        int pos = 0;
        for (int i = 0; i < m; ++i) {
            if (pos < a.size() && a[pos] == i) pos ++;
            else inva.push_back(i);
        }
        solve(inva);
        if (x != -1) x = ((x - 1ll * n * d % m) % m + m) % m;
    }
    if (x == -1) printf("-1\n");
    else printf("%d %d\n", x, d);
    return 0;
}


//be name khoda :)

#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define IINF 0x3f3f3f3f //1061109567
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

inline int in() {int x, y; y = scanf("%d", &x); return x;}

const int N = 1e6 + 213;

bool has[N];
int a[N], n;

int isIn(int x) {
	int ind =lower_bound(a, a + n, x) - a;
	return (a[ind] == x ? ind : -1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int m;
	bool reverse = false;
	cin >> m >> n;
	rep(i, n)
		cin >> a[i];
	if(n == m)
		return cout << 0 << ' ' << 1 << endl, 0;
	if(n == 1)
		return cout << a[0] << ' ' << 1 << endl, 0;
	if(n == m - 1) {
		rep(i, m)
			if(isIn(i) == -1)
				return cout << (i + 1) % m << ' ' << 1 << endl, 0;
	}
	if(m - n < n) {
		reverse = true;
		rep(i, n)
			has[a[i]] = true;
		n = 0;
		rep(i, m)
			if(!has[i])
				a[n++] = i;
	}
	sort(a, a + n);
	for(int i = 1; i < n; i++) {
		int d = a[i] - a[0], siz = 0, first, end;
		int now = a[0], ind = 0;
		while(ind != -1) {
			siz++;
			first = now;
			now = (now - d + m) % m;
			ind = isIn(now);
		}
		now = a[0], ind = 0;
		while(ind != -1) {
			if(ind != 0)
				siz++;
			end = now;
			now = (now + d) % m;
			ind = isIn(now);
		}
		// cerr << d << ' ' << siz << ' ' << first << ' ' << end << ' ' << n << endl;
		if(siz == n) {
			if(reverse)
				return cout << (end + d) % m << ' ' << d << endl, 0;
			else
				return cout << first << ' ' << d << endl, 0;
		}
	}
	cout << -1 << endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


//be name khoda :)

#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define IINF 0x3f3f3f3f //1061109567
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

inline int in() {int x, y; y = scanf("%d", &x); return x;}

const int N = 1e6 + 213;

bool has[N];
int a[N], n;

int isIn(int x) {
	int ind =lower_bound(a, a + n, x) - a;
	return (a[ind] == x ? ind : -1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int m;
	bool reverse = false;
	cin >> m >> n;
	rep(i, n)
		cin >> a[i];
	if(m - n < n) {
		reverse = true;
		rep(i, n)
			has[a[i]] = true;
		n = 0;
		rep(i, m)
			if(!has[i])
				a[n++] = i;
	}
	sort(a, a + n);
	for(int i = 1; i < n; i++) {
		int d = a[i] - a[0], siz = 0, first, end;
		int now = a[0], ind = 0;
		while(ind != -1) {
			siz++;
			first = now;
			now = (now - d + m) % m;
			ind = isIn(now);
		}
		now = a[0], ind = 0;
		while(ind != -1) {
			if(ind != 0)
				siz++;
			end = now;
			now = (now + d) % m;
			ind = isIn(now);
		}
		// cerr << d << ' ' << siz << ' ' << first << ' ' << end << ' ' << n << endl;
		if(siz == n) {
			if(reverse)
				return cout << (end + d) % m << ' ' << d << endl, 0;
			else
				return cout << first << ' ' << d << endl, 0;
		}
	}
	cout << -1 << endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


//be name khoda :)

#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define IINF 0x3f3f3f3f //1061109567
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

inline int in() {int x, y; y = scanf("%d", &x); return x;}

const int N = 1e6 + 213;

bool has[N];
int a[N], n;

int isIn(int x) {
	int ind =lower_bound(a, a + n, x) - a;
	return (a[ind] == x ? ind : -1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int m;
	bool reverse = false;
	cin >> m >> n;
	rep(i, n)
		cin >> a[i];
	if(n == m)
		return cout << 0 << ' ' << 1 << endl, 0;
	if(m - n < n) {
		reverse = true;
		rep(i, n)
			has[a[i]] = true;
		n = 0;
		rep(i, m)
			if(!has[i])
				a[n++] = i;
	}
	sort(a, a + n);
	for(int i = 1; i < n; i++) {
		int d = a[i] - a[0], siz = 0, first, end;
		int now = a[0], ind = 0;
		while(ind != -1) {
			siz++;
			first = now;
			now = (now - d + m) % m;
			ind = isIn(now);
		}
		now = a[0], ind = 0;
		while(ind != -1) {
			if(ind != 0)
				siz++;
			end = now;
			now = (now + d) % m;
			ind = isIn(now);
		}
		// cerr << d << ' ' << siz << ' ' << first << ' ' << end << ' ' << n << endl;
		if(siz == n) {
			if(reverse)
				return cout << (end + d) % m << ' ' << d << endl, 0;
			else
				return cout << first << ' ' << d << endl, 0;
		}
	}
	cout << -1 << endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


//be name khoda :)

#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define IINF 0x3f3f3f3f //1061109567
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

inline int in() {int x, y; y = scanf("%d", &x); return x;}

const int N = 1e6 + 213;

bool has[N];
int a[N], n;

int isIn(int x) {
	int ind = lower_bound(a, a + n, x) - a;
	return (a[ind] == x && ind < n ? ind : -1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int m;
	bool reverse = false;
	cin >> m >> n;
	rep(i, n)
		cin >> a[i];
	sort(a, a + n);
	if(n == m)
		return cout << 0 << ' ' << 1 << endl, 0;
	if(n == 1)
		return cout << a[0] << ' ' << 1 << endl, 0;
	if(n == m - 1) {
		rep(i, m)
			if(isIn(i) == -1)
				return cout << (i + 1) % m << ' ' << 1 << endl, 0;
	}
	if(m - n < n) {
		reverse = true;
		rep(i, n)
			has[a[i]] = true;
		n = 0;
		rep(i, m)
			if(!has[i])
				a[n++] = i;
	}
	sort(a, a + n);
	for(int i = 1; i < n; i++) {
		int d = a[i] - a[0], siz = 0, first, end;
		int now = a[0], ind = 0;
		while(ind != -1) {
			siz++;
			first = now;
			now = (now - d + m) % m;
			ind = isIn(now);
		}
		now = a[0], ind = 0;
		while(ind != -1) {
			if(ind != 0)
				siz++;
			end = now;
			now = (now + d) % m;
			ind = isIn(now);
		}
		// cerr << d << ' ' << siz << ' ' << first << ' ' << end << ' ' << n << endl;
		if(siz == n) {
			if(reverse)
				return cout << (end + d) % m << ' ' << d << endl, 0;
			else
				return cout << first << ' ' << d << endl, 0;
		}
	}
	cout << -1 << endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fst first
#define snd second
#define rep(i, st, ed) for(int i=st; i<(int)ed; i++)
#define repn(i, st, ed) for(int i=st; i<=(int)ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=(int)st; i--)
#define trav(x, v) for(auto &x: v)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define RANDOM_GEN(st, ed)  uniform_int_distribution<int>(st, ed)(rng)
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define popb pop_back

using ll = long long;
using ld = long double;

using pi = pair<int,int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;

using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<ld>;
using vpi = vector<pi>;

const int N = 2e5 + 10;
const int M = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using maxpq = priority_queue<T>;

int mod;
int n;
int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

void solve()
{
	cin >> mod >> n;
    set<int> a, b;
    for(int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        a.insert(x);
    }
    if(n == mod)
    {
        cout << 0 << " " << 1 << '\n';
        return;
    }
    if(n == 1)
    {
        cout << *a.begin() << " " << 1 << '\n';
        return;
    }
    if(n == mod - 1)
    {
        for(int i = 0; i < mod; ++i)
            if(a.find(i) == a.end())
            {
                cout << (i+1) % mod << " " << 1 << '\n';
                return;
            }
    }
    int rev = 0;
    if(2 * n > mod)
    {
        for(int i = 0; i < mod; ++i)
            if(a.find(i) == a.end())
                b.insert(i);
        swap(a, b);
        rev = 1;
        n = a.size();
    }
    int dif = *a.rbegin() - *a.begin();
    int cnt = n;
    for(auto it = a.begin(); it != a.end(); ++it)
        cnt -= (a.find(add(*it, dif)) != a.end());
    dif = mul(dif, pw(cnt, mod-2));
    if(rev)
        swap(a, b);
    b = a;
    int start = *a.begin();
    a.erase(a.begin());
    while(1)
    {
        int nxt = add(start, -dif);
        if(a.find(nxt) == a.end())
            break;
        start = nxt;
        a.erase(start);
    }
    int cur = start;
    while(1)
    {
        if(b.find(cur) == b.end())
        {
            cout << -1 << '\n';
            return;
        }
        b.erase(cur);
        if(b.empty())
            break;
        cur = add(cur, dif);
    }
    cout << start << " " << dif << '\n';
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout << setprecision(12);

	// Write code before test cases

	// solving test cases

	int tests = 1;
	//cin >> tests;
	while(tests--) solve();

#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int Maxn = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int m, n;
int a[Maxn];
int S;

int Inv(int a)
{
	int res = 1, p = m - 2;
	while (p) {
		if (p & 1) res = ll(res) * a % m;
		p >>= 1; a = ll(a) * a % m;
	}
	return res;
}

int main()
{
	scanf("%d %d", &m, &n);
	if (n == m) { printf("0 1\n"); return 0; }
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		S = (S + a[i]) % m;
	}
	if (n == 1) { printf("%d 0\n", a[0]); return 0; }
	int invn = Inv(n), invn1 = Inv(n - 1);
	int C = 2ll * ll(S) % m * invn % m * invn1 % m;
	int D = 2ll * invn1 % m;
	shuffle(a, a + n, rng);
	vector <ii> V;
	for (int i = 0; i < n; i++) {
		int d = (C - ll(a[i]) * D % m + m) % m;
		if (d) V.push_back(ii(Inv(d), a[i]));
	}
	shuffle(V.begin(), V.end(), rng);
	for (int i = 0; i < V.size(); i++) {
        bool ok = true;
        for (int j = 0; j < n; j++) {
            int tp = (a[j] - V[i].second + m) % m;
            ok = ll(tp) * V[i].first % m < n;
            swap(a[j], a[uniform_int_distribution<int>(0, j)(rng)]);
            if (!ok) break;
        }
        if (ok) { printf("%d %d\n", V[i].second, Inv(V[i].first)); return 0; }
	}
	printf("-1\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int Maxn = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int m, n;
int a[Maxn];
int S;

int Inv(int a)
{
	int res = 1, p = m - 2;
	while (p) {
		if (p & 1) res = ll(res) * a % m;
		p >>= 1; a = ll(a) * a % m;
	}
	return res;
}

int main()
{
	scanf("%d %d", &m, &n);
	if (n == m) { printf("0 1\n"); return 0; }
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		S = (S + a[i]) % m;
	}
	if (n == 1) { printf("%d 0\n", a[0]); return 0; }
	int invn = Inv(n), invn1 = Inv(n - 1);
	int C = 2ll * ll(S) % m * invn % m * invn1 % m;
	int D = 2ll * invn1 % m;
	shuffle(a, a + n, rng);
	vector <ii> V;
	for (int i = 0; i < n; i++) {
		int d = (C - ll(a[i]) * D % m + m) % m;
		if (d) V.push_back(ii(Inv(d), a[i]));
	}
	shuffle(V.begin(), V.end(), rng);
	for (int i = 0; i < V.size(); i++) {
        bool ok = true;
        for (int j = 0; j < n; j++) {
            int tp = (a[j] - V[i].second + m) % m;
            ok = ll(tp) * V[i].first % m < n;
            if (!ok) break;
        }
        if (ok) { printf("%d %d\n", V[i].second, Inv(V[i].first)); return 0; }
	}
	printf("-1\n");
    return 0;
}