#include <bits/stdc++.h>   using namespace std;   int GLL(long long& x) { return scanf( %lld , &x); }   int GI(int& x) { return scanf( %d , &x); }   int m, n;   long long add(long long x, long long y) {     x += y;     if (x >= m) x -= m;     return x;   }   long long sub(long long x, long long y) {     x -= y;     if (x < 0) x += m;     return x;   }   long long mul(long long x, long long y) { return (x * y) % m; }   long long powmod(long long a, long long b) {     long long res = 1;     a %= m;     for (; b; b >>= 1) {       if (b & 1) res = res * a % m;       a = a * a % m;     }     return res;   }   bool euler_criterion(long long a, long long p) {     return powmod(a, (p - 1) / 2) == 1;   }   long long tonelli_shanks(long long a, long long p) {     long long q = p - 1;     long long s = 0;     while (q % 2 == 0) {       s++;       q /= 2;     }     long long z = rand() % p;     while (euler_criterion(z, p)) {       z = rand() % p;     }     long long c = powmod(z, q);     long long r = powmod(a, (q + 1) / 2);     long long t = powmod(a, q);     long long m = s;     while (t != 1) {       long long lo = 1, hi = m - 1;       long long i = -1;       while (lo <= hi) {         long long mid = (lo + hi) / 2;         if (powmod(t, 1LL << mid) == 1) {           i = mid;           hi = mid - 1;         } else {           lo = mid + 1;         }       }       long long b = powmod(c, 1LL << (m - i - 1));       r = mul(b, r);       t = mul(t, mul(b, b));       c = mul(b, b);       m = i;     }     return r;   }   const int MAXN = 100005;   long long a[MAXN], d[MAXN], sqrd[MAXN], sumd[MAXN], sumsqrd[MAXN];   long long sumsqr[MAXN];   unordered_set<long long> sa, stest;   int main() {     GI(m);     GI(n);     for (int i = 1; i <= (int)(n); i++) {       GLL(a[i]);       sa.insert(a[i]);     }     if (n == 0) {       printf( %lld 0 n , a[0]);       return 0;     }     memset(d, 0, sizeof d);     memset(sqrd, 0, sizeof sqrd);     memset(sumd, 0, sizeof sumd);     memset(sumsqrd, 0, sizeof sumsqrd);     sort(a + 1, a + n + 1);     long long inv2 = powmod(2, m - 2);     for (int i = 2; i <= n; i++) {       d[i] = add(d[i - 1], mul(a[i] - a[i - 1], i - 1));       sqrd[i] = add(add(sqrd[i - 1], mul(2, mul(a[i] - a[i - 1], d[i - 1]))),                     mul(mul(a[i] - a[i - 1], a[i] - a[i - 1]), i - 1));       sumd[i] = add(sumd[i - 1], d[i]);       sumsqrd[i] = add(sumsqrd[i - 1], sqrd[i]);     }     memset(sumsqr, 0, sizeof sumsqr);     for (int i = 1; i < MAXN; i++) sumsqr[i] = add(sumsqr[i - 1], mul(i, i));     long long c = 0;     for (int i = 1; i <= (int)(n - 1); i++) c = add(c, sumsqr[i]);     long long test2 = mul(sumsqrd[n], powmod(c, m - 2));     if (test2 == 0 || euler_criterion(test2, m)) {       long long test = test2 == 0 ? 1 : tonelli_shanks(test2, m);       int fwd = 0;       long long curr = add(a[1], test);       while (curr != a[1] && sa.find(curr) != sa.end()) {         fwd++;         curr = add(curr, test);       }       int bwd = 0;       curr = sub(a[1], test);       while (curr != a[1] && sa.find(curr) != sa.end()) {         bwd++;         curr = sub(curr, test);       }       if (fwd + bwd + 1 >= n) {         curr = add(curr, test);         printf( %lld %lld n , curr, test);       } else {         printf( -1 n );       }     } else {       printf( -1 n );       return 0;     }     return 0;   }   