#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define mx 700000
#define ll long long

vector<int>ara[mx];
set<pii>mylist[mx],query[mx];
int P[mx][22],L[mx],ans[mx],len[mx];
int parentanse[mx];
pii roo;
int dia=0;
vector<int>vc[mx];
int start[mx],pos;
int dfs(int v,int par,int lev)
{
    ara[lev].pb(v);
    start[v]=++pos;
    L[v]=lev;
    P[v][0]=par;
    dia=max(dia,lev);
    roo=max(roo,mp(lev,v));
    int ret=0;
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        int x=dfs(w,v,lev+1);
        ret=max(ret,x);

        mylist[v].insert(mp(x,w));
    }
    len[v]=ret;
    return ret+1;
}
void dfs2(int v,int par,int ansi)
{
    parentanse[v]=ansi;
    ansi=max(ansi,0);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
            set<pii>::iterator it;
        mylist[v].erase(mp(len[w]+1,w));
        int c=ansi;
        if(mylist[v].size())
        {
            it=mylist[v].end();
            it--;
            pii ps=*it;
            c=max(c,ps.fs);
        }
        dfs2(w,v,c+1);
        mylist[v].insert(mp(len[w]+1,w));
    }
}
void dfs3(int v,int par,int lev)
{
    dia=max(dia,lev);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        dfs3(w,v,lev+1);
    }
}
int lca_query(int p, int q)
{
    int tmp, log, i;

    if (L[p] < L[q])
        tmp = p, p = q, q = tmp;

    log=1;
    while(1)
    {
        int next=log+1;
        if((1<<next)>L[p])
            break;
        log++;

    }

    for (i = log; i >= 0; i--)
        if (L[p] - (1 << i) >= L[q])
            p = P[p][i];

    if (p == q)
        return p;

    for (i = log; i >= 0; i--)
        if (P[p][i] != -1 && P[p][i] != P[q][i])
            p = P[p][i], q = P[q][i];

    return P[p][0];
}
void prc(set<int>&dum,set<pii>&my,int lev,int v)
{
   ans[lev*2-L[v]*2]=max(ans[lev*2-L[v]*2],(int)dum.size());
   int g= dum.size();

   if(my.size())
   {
      set<pii>::iterator it3;
      it3=my.end();
      it3--;
      pii rs=*it3;
      if(rs.fs<lev-1-L[v])g--;
   }
   else g--;
   ans[lev-1+lev-L[v]*2]=max(ans[lev-1+lev-L[v]*2],g+1);
}
void process(int v)
{
    set<pii>::iterator it,it2;
    set<int>::iterator it3;
    for(it=query[v].begin();it!=query[v].end();)
    {
        it2=it;
        pii ps=*it;
        set<int>dum;
      //  cout<<ps.fs<<endl;
        for(;it2!=query[v].end();it2++)
        {
           pii rs=*it2;
           if(rs.fs!=ps.fs)break;
           mylist[v].erase({len[rs.sc]+1,rs.sc});
           dum.insert(rs.sc);
        }
      //  cout<<dum.size()<<endl;
        mylist[v].insert(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v])dum.insert(P[v][0]);
        else mylist[v].insert(mp(parentanse[v],P[v][0]));
        prc(dum,mylist[v],ps.fs,v);
        mylist[v].erase(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v]);
        else mylist[v].erase(mp(parentanse[v],P[v][0]));
        it=it2;
        for(it3=dum.begin();it3!=dum.end();it3++)
        {
           int gs=*it3;
           if(gs==P[v][0])continue;
           mylist[v].insert(mp(len[gs]+1,gs));
        }
    }
}
int findo(int c,int x)
{
    if(L[c]==x)return c;
    for(int i=19;i>=0;i--)
    {
       if(P[c][i]==-1)continue;
       if(L[P[c][i]]>x){
         c=P[c][i];
       }
    }
    return P[c][0];

}
#define tii pair<pii,int>
vector<pii>chum[mx];
int query_bin(int v,int c)
{
   int x=chum[v].size();
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   return x-g;
}
int main()
{
    memset(P,-1,sizeof P);

    int n,l,k;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       scanf("%d%d",&l,&k);
       vc[l].pb(k);
       vc[k].pb(l);
    }
     dfs(1,-1,0);
    dfs2(1,-1,-1);
    dfs3(roo.sc,-1,0);
    for(int j=1; (1<<j)<=n; j++)
    {
        for(int i=1; i<=n; i++)
        {
            if(P[i][j-1]==-1)
                continue;
            P[i][j]=P[P[i][j-1]][j-1];
        }
    }
  //  cout<<ara[1].size()<<endl;
    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<ara[i].size(); j++)
        {
            int lc=lca_query(ara[i][j-1],ara[i][j]);
            query[lc].insert({i,findo(ara[i][j-1],L[lc]+1)});
            query[lc].insert({i,findo(ara[i][j],L[lc]+1)});
            //if(i==1)cout<<lc<<" "<<ara[i][j-1]<<" "<<ara[i][j]<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
       if(query[i].size()==0)continue;
    //  cout<<query[i].size()<<endl;
   // cout<<i<<endl;
       process(i);
   //    cout<<ans[3]<<endl;
       query[i].clear();
    }
  //  cout<<ans[3]<<endl;
    for(int i=1;i<=n;i++)
    {
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           chum[i].pb(*it);
       }
       sort(chum[i].begin(),chum[i].end());
    }
 //   cout<<ans[6]<<endl;
    for(int i=1;i<=n;i++){
    vector<tii>tmp;
       for(int j=0;j<ara[i].size();j++)
       {
          int c=ara[i][j];
          tmp.pb({{start[c],c},0});
       }
        for(int j=0;j<ara[i+1].size();j++)
       {
          int c=ara[i+1][j];
          tmp.pb({{start[c],c},1});
       }
       sort(tmp.rbegin(),tmp.rend());
       int toxic[2];
       toxic[0]=-1;
       toxic[1]=-1;
       for(int j=0;j<tmp.size();j++)
       {
          int c=tmp[j].fs.sc;
          int x=tmp[j].sc;
          if(toxic[x^1]!=-1)
          {
             int lca=lca_query(toxic[x^1],c);
             int f=findo(c,L[lca]+1);
             int g=findo(toxic[x^1],L[lca]+1);
             if(lca==c||lca==toxic[x^1]);
             else{
          //   cout<<lca<<" "<<g<<" "<<f<<" "<<c<<" "<<toxic[x^1]<<endl;
             int tar;
             tar=f;
             //else tar=g;
             int koyta=query_bin(tar,i-L[tar]+1);
              koyta+=query_bin(lca,i-L[lca]);
              if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
                tar=g;
             //else tar=g;

              koyta=query_bin(tar,i-L[tar]+1);
            //  cout<<lca<<" "<<tar<<" "<<f<<" "<<g<<" "<<koyta<<" "<<endl;
              koyta+=query_bin(lca,i-L[lca]);
               if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
          }
          }
          toxic[x]=c;

       }

    }
    for(int i=1;i<=n;i++)
    {
      ans[1]=max(ans[1],(int)vc[i].size()+1);
    }
    for(int i=1;i<=n;i++)
    {
      ans[i]=max(ans[i],1);
      if(i<=dia)ans[i]=max(ans[i],2);
      printf("%d ",ans[i]);
    }

}


#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define mx 700000
#define ll long long

vector<int>ara[mx];
set<pii>mylist[mx],query[mx];
int P[mx][22],L[mx],ans[mx],len[mx];
int parentanse[mx];
pii roo;
int dia=0;
vector<int>vc[mx];
int start[mx],pos;
int dfs(int v,int par,int lev)
{
    ara[lev].pb(v);
    start[v]=++pos;
    L[v]=lev;
    P[v][0]=par;
    dia=max(dia,lev);
    roo=max(roo,mp(lev,v));
    int ret=0;
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        int x=dfs(w,v,lev+1);
        ret=max(ret,x);

        mylist[v].insert(mp(x,w));
    }
    len[v]=ret;
    return ret+1;
}
void dfs2(int v,int par,int ansi)
{
    parentanse[v]=ansi;
    ansi=max(ansi,0);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
            set<pii>::iterator it;
        mylist[v].erase(mp(len[w]+1,w));
        int c=ansi;
        if(mylist[v].size())
        {
            it=mylist[v].end();
            it--;
            pii ps=*it;
            c=max(c,ps.fs);
        }
        dfs2(w,v,c+1);
        mylist[v].insert(mp(len[w]+1,w));
    }
}
void dfs3(int v,int par,int lev)
{
    dia=max(dia,lev);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        dfs3(w,v,lev+1);
    }
}
int lca_query(int p, int q)
{
    int tmp, log, i;

    if (L[p] < L[q])
        tmp = p, p = q, q = tmp;

    log=1;
    while(1)
    {
        int next=log+1;
        if((1<<next)>L[p])
            break;
        log++;

    }

    for (i = log; i >= 0; i--)
        if (L[p] - (1 << i) >= L[q])
            p = P[p][i];

    if (p == q)
        return p;

    for (i = log; i >= 0; i--)
        if (P[p][i] != -1 && P[p][i] != P[q][i])
            p = P[p][i], q = P[q][i];

    return P[p][0];
}
void prc(set<int>&dum,set<pii>&my,int lev,int v)
{
   ans[lev*2-L[v]*2]=max(ans[lev*2-L[v]*2],(int)dum.size());
   int g= dum.size();

   if(my.size())
   {
      set<pii>::iterator it3;
      it3=my.end();
      it3--;
      pii rs=*it3;
      if(rs.fs!=lev-1-L[v])g--;
   }
   else g--;
   ans[lev-1+lev-L[v]*2]=max(ans[lev-1+lev-L[v]*2],g+1);
}
void process(int v)
{
    set<pii>::iterator it,it2;
    set<int>::iterator it3;
    for(it=query[v].begin();it!=query[v].end();)
    {
        it2=it;
        pii ps=*it;
        set<int>dum;
      //  cout<<ps.fs<<endl;
        for(;it2!=query[v].end();it2++)
        {
           pii rs=*it2;
           if(rs.fs!=ps.fs)break;
           mylist[v].erase({len[rs.sc]+1,rs.sc});
           dum.insert(rs.sc);
        }
      //  cout<<dum.size()<<endl;
        mylist[v].insert(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v])dum.insert(P[v][0]);
        else mylist[v].insert(mp(parentanse[v],P[v][0]));
        prc(dum,mylist[v],ps.fs,v);
        mylist[v].erase(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v]);
        else mylist[v].erase(mp(parentanse[v],P[v][0]));
        it=it2;
        for(it3=dum.begin();it3!=dum.end();it3++)
        {
           int gs=*it3;
           if(gs==P[v][0])continue;
           mylist[v].insert(mp(len[gs]+1,gs));
        }
    }
}
int findo(int c,int x)
{
    if(L[c]==x)return c;
    for(int i=19;i>=0;i--)
    {
       if(P[c][i]==-1)continue;
       if(L[P[c][i]]>x){
         c=P[c][i];
       }
    }
    return P[c][0];

}
#define tii pair<pii,int>
vector<pii>chum[mx];
int query_bin(int v,int c)
{
   int x=chum[v].size();
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   return x-g;
}
int main()
{
    memset(P,-1,sizeof P);

    int n,l,k;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       scanf("%d%d",&l,&k);
       vc[l].pb(k);
       vc[k].pb(l);
    }
     dfs(1,-1,0);
    dfs2(1,-1,-1);
    dfs3(roo.sc,-1,0);
    for(int j=1; (1<<j)<=n; j++)
    {
        for(int i=1; i<=n; i++)
        {
            if(P[i][j-1]==-1)
                continue;
            P[i][j]=P[P[i][j-1]][j-1];
        }
    }
  //  cout<<ara[1].size()<<endl;
    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<ara[i].size(); j++)
        {
            int lc=lca_query(ara[i][j-1],ara[i][j]);
            query[lc].insert({i,findo(ara[i][j-1],L[lc]+1)});
            query[lc].insert({i,findo(ara[i][j],L[lc]+1)});
            //if(i==1)cout<<lc<<" "<<ara[i][j-1]<<" "<<ara[i][j]<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
       if(query[i].size()==0)continue;
    //  cout<<query[i].size()<<endl;
   // cout<<i<<endl;
       process(i);
   //    cout<<ans[3]<<endl;
       query[i].clear();
    }
  //  cout<<ans[3]<<endl;
    for(int i=1;i<=n;i++)
    {
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           chum[i].pb(*it);
       }
       sort(chum[i].begin(),chum[i].end());
    }
    for(int i=1;i<=n;i++){
    vector<tii>tmp;
       for(int j=0;j<ara[i].size();j++)
       {
          int c=ara[i][j];
          tmp.pb({{start[c],c},0});
       }
        for(int j=0;j<ara[i+1].size();j++)
       {
          int c=ara[i+1][j];
          tmp.pb({{start[c],c},1});
       }
       sort(tmp.rbegin(),tmp.rend());
       int toxic[2];
       toxic[0]=-1;
       toxic[1]=-1;
       for(int j=0;j<tmp.size();j++)
       {
          int c=tmp[j].fs.sc;
          int x=tmp[j].sc;
          if(toxic[x^1]!=-1)
          {
             int lca=lca_query(toxic[x^1],c);
             int f=findo(c,L[lca]+1);
             int g=findo(toxic[x^1],L[lca]+1);
          //   cout<<lca<<" "<<g<<" "<<f<<" "<<c<<" "<<toxic[x^1]<<endl;
             int tar;
             tar=f;
             //else tar=g;
             int koyta=query_bin(tar,i);
              koyta+=query_bin(lca,i);
              koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
                tar=g;
             //else tar=g;

              koyta=query_bin(tar,i);
            //  cout<<lca<<" "<<tar<<" "<<f<<" "<<g<<" "<<koyta<<" "<<endl;
              koyta+=query_bin(lca,i);
              koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
          }
          toxic[x]=c;

       }

    }

    for(int i=1;i<=n;i++)
    {
      ans[i]=max(ans[i],1);
      if(i<=dia)ans[i]=max(ans[i],2);
      printf("%d ",ans[i]);
    }

}


#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define mx 700000
#define ll long long

vector<int>ara[mx];
set<pii>mylist[mx],query[mx];
int P[mx][22],L[mx],ans[mx],len[mx];
int parentanse[mx];
pii roo;
int dia=0;
vector<int>vc[mx];
int start[mx],pos;
int dfs(int v,int par,int lev)
{
    ara[lev].pb(v);
    start[v]=++pos;
    L[v]=lev;
    P[v][0]=par;
    dia=max(dia,lev);
    roo=max(roo,mp(lev,v));
    int ret=0;
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        int x=dfs(w,v,lev+1);
        ret=max(ret,x);

        mylist[v].insert(mp(x,w));
    }
    len[v]=ret;
    return ret+1;
}
void dfs2(int v,int par,int ansi)
{
    parentanse[v]=ansi;
    ansi=max(ansi,0);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
            set<pii>::iterator it;
        mylist[v].erase(mp(len[w]+1,w));
        int c=ansi;
        if(mylist[v].size())
        {
            it=mylist[v].end();
            it--;
            pii ps=*it;
            c=max(c,ps.fs);
        }
        dfs2(w,v,c+1);
        mylist[v].insert(mp(len[w]+1,w));
    }
}
void dfs3(int v,int par,int lev)
{
    dia=max(dia,lev);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        dfs3(w,v,lev+1);
    }
}
int lca_query(int p, int q)
{
    int tmp, log, i;

    if (L[p] < L[q])
        tmp = p, p = q, q = tmp;

    log=1;
    while(1)
    {
        int next=log+1;
        if((1<<next)>L[p])
            break;
        log++;

    }

    for (i = log; i >= 0; i--)
        if (L[p] - (1 << i) >= L[q])
            p = P[p][i];

    if (p == q)
        return p;

    for (i = log; i >= 0; i--)
        if (P[p][i] != -1 && P[p][i] != P[q][i])
            p = P[p][i], q = P[q][i];

    return P[p][0];
}
void prc(set<int>&dum,set<pii>&my,int lev,int v)
{
   ans[lev*2-L[v]*2]=max(ans[lev*2-L[v]*2],(int)dum.size());
   int g= dum.size();

   if(my.size())
   {
      set<pii>::iterator it3;
      it3=my.end();
      it3--;
      pii rs=*it3;
      if(rs.fs<lev-1-L[v])g--;
   }
   else g--;
   ans[lev-1+lev-L[v]*2]=max(ans[lev-1+lev-L[v]*2],g+1);
}
void process(int v)
{
    set<pii>::iterator it,it2;
    set<int>::iterator it3;
    for(it=query[v].begin();it!=query[v].end();)
    {
        it2=it;
        pii ps=*it;
        set<int>dum;
      //  cout<<ps.fs<<endl;
        for(;it2!=query[v].end();it2++)
        {
           pii rs=*it2;
           if(rs.fs!=ps.fs)break;
           mylist[v].erase({len[rs.sc]+1,rs.sc});
           dum.insert(rs.sc);
        }
      //  cout<<dum.size()<<endl;
        mylist[v].insert(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v])dum.insert(P[v][0]);
        else mylist[v].insert(mp(parentanse[v],P[v][0]));
        prc(dum,mylist[v],ps.fs,v);
        mylist[v].erase(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v]);
        else mylist[v].erase(mp(parentanse[v],P[v][0]));
        it=it2;
        for(it3=dum.begin();it3!=dum.end();it3++)
        {
           int gs=*it3;
           if(gs==P[v][0])continue;
           mylist[v].insert(mp(len[gs]+1,gs));
        }
    }
}
int findo(int c,int x)
{
    if(L[c]==x)return c;
    for(int i=20;i>=0;i--)
    {
       if(P[c][i]==-1)continue;
       if(L[P[c][i]]>x){
         c=P[c][i];
       }
    }
    return P[c][0];

}
#define tii pair<pii,int>
vector<pii>chum[mx];
int query_bin(int v,int c)
{
   int x=chum[v].size();
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   return x-g;
}
int lo_bo(int v,int c)
{
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   if(g==chum[v].size()==0||chum[v][g].fs!=c)return 0;
   return 1;

}
int main()
{
    memset(P,-1,sizeof P);

    int n,l,k;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       scanf("%d%d",&l,&k);
       vc[l].pb(k);
       vc[k].pb(l);
    }
     dfs(1,-1,0);
    dfs2(1,-1,-1);
    dfs3(roo.sc,-1,0);
    for(int j=1; (1<<j)<=n; j++)
    {
        for(int i=1; i<=n; i++)
        {
            if(P[i][j-1]==-1)
                continue;
            P[i][j]=P[P[i][j-1]][j-1];
        }
    }
  //  cout<<ara[1].size()<<endl;
    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<ara[i].size(); j++)
        {
            int lc=lca_query(ara[i][j-1],ara[i][j]);
            query[lc].insert({i,findo(ara[i][j-1],L[lc]+1)});
            query[lc].insert({i,findo(ara[i][j],L[lc]+1)});
            //if(i==1)cout<<lc<<" "<<ara[i][j-1]<<" "<<ara[i][j]<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
       if(query[i].size()==0)continue;
    //  cout<<query[i].size()<<endl;
   // cout<<i<<endl;
       process(i);
   //    cout<<ans[3]<<endl;
       query[i].clear();
    }
  //  cout<<ans[3]<<endl;
    for(int i=1;i<=n;i++)
    {
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           chum[i].pb(*it);
       }
       sort(chum[i].begin(),chum[i].end());
    }
 //   cout<<ans[6]<<endl;
    for(int i=1;i<=n;i++){
    vector<tii>tmp;
       for(int j=0;j<ara[i].size();j++)
       {
          int c=ara[i][j];
          tmp.pb({{start[c],c},0});
       }
        for(int j=0;j<ara[i+1].size();j++)
       {
          int c=ara[i+1][j];
          tmp.pb({{start[c],c},1});
       }
       sort(tmp.rbegin(),tmp.rend());
       int toxic[2];
       toxic[0]=-1;
       toxic[1]=-1;
       for(int j=0;j<tmp.size();j++)
       {
          int c=tmp[j].fs.sc;
          int x=tmp[j].sc;
          if(toxic[x^1]!=-1)
          {
             int lca=lca_query(toxic[x^1],c);
             int f=findo(c,L[lca]+1);
             int g=findo(toxic[x^1],L[lca]+1);
             if(lca==c||lca==toxic[x^1]);
             else{
          //   cout<<lca<<" "<<g<<" "<<f<<" "<<c<<" "<<toxic[x^1]<<endl;
             int tar;
             tar=f;
             //else tar=g;
             int koyta=query_bin(tar,i-L[tar]+1);
              koyta+=query_bin(lca,i-L[lca]);
              if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
                tar=g;
             //else tar=g;

              koyta=query_bin(tar,i-L[tar]+1);
            //  cout<<lca<<" "<<tar<<" "<<f<<" "<<g<<" "<<koyta<<" "<<endl;
              koyta+=query_bin(lca,i-L[lca]);
               if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);

              int ko=query_bin(lca,i+1-L[lca]);
              if(parentanse[lca]>=i+1-L[lca])ko++;
              if(lo_bo(lca,i-L[lca])||parentanse[lca]==i-L[lca]);
              else ko--;
              ans[i+1+i-2*L[lca]]=max(ans[i+1+i-2*L[lca]],ko+1);
          }
          }
          toxic[x]=c;

       }

    }
    for(int i=1;i<=n;i++)
    {
      ans[1]=max(ans[1],(int)vc[i].size()+1);
    }
    for(int i=1;i<=n;i++)
    {
      ans[i]=max(ans[i],1);
      if(i<=dia)ans[i]=max(ans[i],2);
      printf("%d ",ans[i]);
    }

}


#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define mx 700000
#define ll long long

vector<int>ara[mx];
set<pii>mylist[mx],query[mx];
int P[mx][22],L[mx],ans[mx],len[mx];
int parentanse[mx];
pii roo;
int dia=0;
vector<int>vc[mx];
int start[mx],pos,en[mx];
int dfs(int v,int par,int lev)
{
    ara[lev].pb(v);
    start[v]=++pos;
    L[v]=lev;
    P[v][0]=par;
    dia=max(dia,lev);
    roo=max(roo,mp(lev,v));
    int ret=0;
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        int x=dfs(w,v,lev+1);
        ret=max(ret,x);

        mylist[v].insert(mp(x,w));
    }
    len[v]=ret;
    en[v]=pos;
    return ret+1;
}
void dfs2(int v,int par,int ansi)
{
    parentanse[v]=ansi;
    ansi=max(ansi,0);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
            set<pii>::iterator it;
        mylist[v].erase(mp(len[w]+1,w));
        int c=ansi;
        if(mylist[v].size())
        {
            it=mylist[v].end();
            it--;
            pii ps=*it;
            c=max(c,ps.fs);
        }
        dfs2(w,v,c+1);
        mylist[v].insert(mp(len[w]+1,w));
    }
}
void dfs3(int v,int par,int lev)
{
    dia=max(dia,lev);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        dfs3(w,v,lev+1);
    }
}
int lca_query(int p, int q)
{
    int tmp, log, i;

    if (L[p] < L[q])
        tmp = p, p = q, q = tmp;

    log=1;
    while(1)
    {
        int next=log+1;
        if((1<<next)>L[p])
            break;
        log++;

    }

    for (i = log; i >= 0; i--)
        if (L[p] - (1 << i) >= L[q])
            p = P[p][i];

    if (p == q)
        return p;

    for (i = log; i >= 0; i--)
        if (P[p][i] != -1 && P[p][i] != P[q][i])
            p = P[p][i], q = P[q][i];

    return P[p][0];
}
void prc(set<int>&dum,set<pii>&my,int lev,int v)
{
   ans[lev*2-L[v]*2]=max(ans[lev*2-L[v]*2],(int)dum.size());
   int g= dum.size();

   if(my.size())
   {
      set<pii>::iterator it3;
      it3=my.end();
      it3--;
      pii rs=*it3;
      if(rs.fs<lev-1-L[v])g--;
   }
   else g--;
   ans[lev-1+lev-L[v]*2]=max(ans[lev-1+lev-L[v]*2],g+1);
}
void process(int v)
{
    set<pii>::iterator it,it2;
    set<int>::iterator it3;
    for(it=query[v].begin();it!=query[v].end();)
    {
        it2=it;
        pii ps=*it;
        set<int>dum;
      //  cout<<ps.fs<<endl;
        for(;it2!=query[v].end();it2++)
        {
           pii rs=*it2;
           if(rs.fs!=ps.fs)break;
           mylist[v].erase({len[rs.sc]+1,rs.sc});
           dum.insert(rs.sc);
        }
      //  cout<<dum.size()<<endl;
        mylist[v].insert(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v])dum.insert(P[v][0]);
        else mylist[v].insert(mp(parentanse[v],P[v][0]));
        prc(dum,mylist[v],ps.fs,v);
        mylist[v].erase(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v]);
        else mylist[v].erase(mp(parentanse[v],P[v][0]));
        it=it2;
        for(it3=dum.begin();it3!=dum.end();it3++)
        {
           int gs=*it3;
           if(gs==P[v][0])continue;
           mylist[v].insert(mp(len[gs]+1,gs));
        }
    }
}
int findo(int c,int x)
{
    if(L[c]==x)return c;
    for(int i=20;i>=0;i--)
    {
       if(P[c][i]==-1)continue;
       if(L[P[c][i]]>x){
         c=P[c][i];
       }
    }
    return P[c][0];

}
#define tii pair<pii,int>
vector<pii>chum[mx];
int query_bin(int v,int c)
{
   int x=chum[v].size();
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   return x-g;
}
int lo_bo(int v,int c)
{
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   if(g==chum[v].size()==0||chum[v][g].fs!=c)return 0;
   return 1;

}
int main()
{
    memset(P,-1,sizeof P);

    int n,l,k;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       scanf("%d%d",&l,&k);
       vc[l].pb(k);
       vc[k].pb(l);
    }
     dfs(1,-1,0);
    dfs2(1,-1,-1);
    dfs3(roo.sc,-1,0);
    for(int j=1; (1<<j)<=n; j++)
    {
        for(int i=1; i<=n; i++)
        {
            if(P[i][j-1]==-1)
                continue;
            P[i][j]=P[P[i][j-1]][j-1];
        }
    }
  //  cout<<ara[1].size()<<endl;
    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<ara[i].size(); j++)
        {
            int lc=lca_query(ara[i][j-1],ara[i][j]);
            query[lc].insert({i,findo(ara[i][j-1],L[lc]+1)});
            query[lc].insert({i,findo(ara[i][j],L[lc]+1)});
            //if(i==1)cout<<lc<<" "<<ara[i][j-1]<<" "<<ara[i][j]<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
       if(query[i].size()==0)continue;
    //  cout<<query[i].size()<<endl;
   // cout<<i<<endl;
       process(i);
   //    cout<<ans[3]<<endl;
       query[i].clear();
    }
  //  cout<<ans[3]<<endl;
    for(int i=1;i<=n;i++)
    {
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           chum[i].pb(*it);
       }
       sort(chum[i].begin(),chum[i].end());
    }
 //   cout<<ans[6]<<endl;
    for(int i=1;i<=n;i++){
    vector<tii>tmp;
       for(int j=0;j<ara[i].size();j++)
       {
          int c=ara[i][j];
          tmp.pb({{start[c],c},0});
       }
        for(int j=0;j<ara[i+1].size();j++)
       {
          int c=ara[i+1][j];
          tmp.pb({{start[c],c},1});
       }
       sort(tmp.rbegin(),tmp.rend());
       vector<int>toxic2[2];
       for(int j=0;j<tmp.size();j++)
       {
          int c=tmp[j].fs.sc;
          int x=tmp[j].sc;
          int r=-1;
          for(int j=(int)toxic2[x^1].size()-1;j>=0;j--)
          {
             int w=toxic2[x^1][j];
             if(start[w]>start[c]||en[w]<start[c]){
               r=w;
               break;
             }
          }
          if(r!=-1)
          {
             int lca=lca_query(r,c);
             int f=findo(c,L[lca]+1);
             int g=findo(r,L[lca]+1);
             if(lca==c||lca==r);
             else{
          //   cout<<lca<<" "<<g<<" "<<f<<" "<<c<<" "<<toxic[x^1]<<endl;
             int tar;
             tar=f;
             //else tar=g;
             int koyta=query_bin(tar,i-L[tar]+1);
              koyta+=query_bin(lca,i-L[lca]);
              if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
                tar=g;
             //else tar=g;

              koyta=query_bin(tar,i-L[tar]+1);
            //  cout<<lca<<" "<<tar<<" "<<f<<" "<<g<<" "<<koyta<<" "<<endl;
              koyta+=query_bin(lca,i-L[lca]);
               if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);

              int ko=query_bin(lca,i+1-L[lca]);
              if(parentanse[lca]>=i+1-L[lca])ko++;
              if(lo_bo(lca,i-L[lca])||parentanse[lca]==i-L[lca]);
              else ko--;
              ans[i+1+i-2*L[lca]]=max(ans[i+1+i-2*L[lca]],ko+1);
          }
          }
          toxic2[x].pb(c);

       }

    }
    for(int i=1;i<=n;i++)
    {
      ans[1]=max(ans[1],(int)vc[i].size()+1);
    }
    for(int i=1;i<=n;i++)
    {
      ans[i]=max(ans[i],1);
      if(i<=dia)ans[i]=max(ans[i],2);
      printf("%d ",ans[i]);
    }

}


#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define mx 700000
#define ll long long

vector<int>ara[mx];
set<pii>mylist[mx],query[mx];
int P[mx][22],L[mx],ans[mx],len[mx];
int parentanse[mx];
pii roo;
int dia=0;
vector<int>vc[mx];
int start[mx],pos,en[mx];
int dfs(int v,int par,int lev)
{
    ara[lev].pb(v);
    start[v]=++pos;
    L[v]=lev;
    P[v][0]=par;
    dia=max(dia,lev);
    roo=max(roo,mp(lev,v));
    int ret=0;
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        int x=dfs(w,v,lev+1);
        ret=max(ret,x);

        mylist[v].insert(mp(x,w));
    }
    len[v]=ret;
    en[v]=pos;
    return ret+1;
}
void dfs2(int v,int par,int ansi)
{
    parentanse[v]=ansi;
    ansi=max(ansi,0);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
            set<pii>::iterator it;
        mylist[v].erase(mp(len[w]+1,w));
        int c=ansi;
        if(mylist[v].size())
        {
            it=mylist[v].end();
            it--;
            pii ps=*it;
            c=max(c,ps.fs);
        }
        dfs2(w,v,c+1);
        mylist[v].insert(mp(len[w]+1,w));
    }
}
void dfs3(int v,int par,int lev)
{
    dia=max(dia,lev);
    for(int i=0; i<vc[v].size(); i++)
    {
        int w=vc[v][i];
        if(w==par)
            continue;
        dfs3(w,v,lev+1);
    }
}
int lca_query(int p, int q)
{
    int tmp, log, i;

    if (L[p] < L[q])
        tmp = p, p = q, q = tmp;

    log=1;
    while(1)
    {
        int next=log+1;
        if((1<<next)>L[p])
            break;
        log++;

    }

    for (i = log; i >= 0; i--)
        if (L[p] - (1 << i) >= L[q])
            p = P[p][i];

    if (p == q)
        return p;

    for (i = log; i >= 0; i--)
        if (P[p][i] != -1 && P[p][i] != P[q][i])
            p = P[p][i], q = P[q][i];

    return P[p][0];
}
void prc(set<int>&dum,set<pii>&my,int lev,int v)
{
   ans[lev*2-L[v]*2]=max(ans[lev*2-L[v]*2],(int)dum.size());
   int g= dum.size();

   if(my.size())
   {
      set<pii>::iterator it3;
      it3=my.end();
      it3--;
      pii rs=*it3;
      if(rs.fs<lev-1-L[v])g--;
   }
   else g--;
   ans[lev-1+lev-L[v]*2]=max(ans[lev-1+lev-L[v]*2],g+1);
}
void process(int v)
{
    set<pii>::iterator it,it2;
    set<int>::iterator it3;
    for(it=query[v].begin();it!=query[v].end();)
    {
        it2=it;
        pii ps=*it;
        set<int>dum;
      //  cout<<ps.fs<<endl;
        for(;it2!=query[v].end();it2++)
        {
           pii rs=*it2;
           if(rs.fs!=ps.fs)break;
           mylist[v].erase({len[rs.sc]+1,rs.sc});
           dum.insert(rs.sc);
        }
      //  cout<<dum.size()<<endl;
        mylist[v].insert(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v])dum.insert(P[v][0]);
        else mylist[v].insert(mp(parentanse[v],P[v][0]));
        prc(dum,mylist[v],ps.fs,v);
        mylist[v].erase(mp(0,v));
        if(parentanse[v]>=ps.fs-L[v]);
        else mylist[v].erase(mp(parentanse[v],P[v][0]));
        it=it2;
        for(it3=dum.begin();it3!=dum.end();it3++)
        {
           int gs=*it3;
           if(gs==P[v][0])continue;
           mylist[v].insert(mp(len[gs]+1,gs));
        }
    }
}
int findo(int c,int x)
{
    assert(L[c]>=x);
    if(L[c]==x)return c;
    for(int i=20;i>=0;i--)
    {
       if(P[c][i]==-1)continue;
       if(L[P[c][i]]>x){
         c=P[c][i];
       }
    }
    return P[c][0];

}
#define tii pair<pii,int>
vector<pii>chum[mx];
int query_bin(int v,int c)
{
   int x=chum[v].size();
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   return x-g;
}
int lo_bo(int v,int c)
{
   int g=upper_bound(chum[v].begin(),chum[v].end(),mp(c-1,INT_MAX))-chum[v].begin();
   if(g==chum[v].size()||chum[v][g].fs!=c)return 0;
   return 1;

}
//int jargon[mx];
int main()
{
    memset(P,-1,sizeof P);

    int n,l,k;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       scanf("%d%d",&l,&k);
       vc[l].pb(k);
       vc[k].pb(l);
    }
     dfs(1,-1,0);
    dfs2(1,-1,-1);
    dfs3(roo.sc,-1,0);
    for(int j=1; (1<<j)<=n; j++)
    {
        for(int i=1; i<=n; i++)
        {
            if(P[i][j-1]==-1)
                continue;
            P[i][j]=P[P[i][j-1]][j-1];
        }
    }
  //  cout<<ara[1].size()<<endl;
    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<ara[i].size(); j++)
        {
            int lc=lca_query(ara[i][j-1],ara[i][j]);
            query[lc].insert({i,findo(ara[i][j-1],L[lc]+1)});
            query[lc].insert({i,findo(ara[i][j],L[lc]+1)});
            //if(i==1)cout<<lc<<" "<<ara[i][j-1]<<" "<<ara[i][j]<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
       if(query[i].size()==0)continue;
    //  cout<<query[i].size()<<endl;
   // cout<<i<<endl;
       process(i);
   //    cout<<ans[3]<<endl;
       query[i].clear();
    }
  //  cout<<ans[3]<<endl;
    for(int i=1;i<=n;i++)
    {
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           chum[i].pb(*it);
       }
       //sort(chum[i].begin(),chum[i].end());
    }
 //   cout<<ans[6]<<endl;
    for(int i=1;i<=n;i++){
    vector<tii>tmp;
       for(int j=0;j<ara[i].size();j++)
       {
          int c=ara[i][j];
          tmp.pb({{start[c],c},0});
       }
        for(int j=0;j<ara[i+1].size();j++)
       {
          int c=ara[i+1][j];
          tmp.pb({{start[c],c},1});
       }
       sort(tmp.begin(),tmp.end());
       vector<int>toxic2[2];
       for(int j=0;j<tmp.size();j++)
       {
          int c=tmp[j].fs.sc;
          int x=tmp[j].sc;
          int r=-1;
          for(int j=(int)toxic2[x^1].size()-1;j>=0;j--)
          {
             int w=toxic2[x^1][j];
               if(start[w]<=start[c]&&en[w]>=start[c])continue;
               r=w;
               break;

          }
          if(r!=-1)
          {
             int lca=lca_query(r,c);
             int f=findo(c,L[lca]+1);
             int g=findo(r,L[lca]+1);
             if(lca==c||lca==r);
             else{
          //   cout<<lca<<" "<<g<<" "<<f<<" "<<c<<" "<<toxic[x^1]<<endl;
             int tar;
             tar=f;
             //else tar=g;
             assert(L[f]-L[lca]==1&&L[g]-L[lca]==1);
             int koyta=query_bin(tar,i-L[tar]+1);
              koyta+=query_bin(lca,i-L[lca]);
              if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);
                tar=g;
             //else tar=g;

              koyta=query_bin(tar,i-L[tar]+1);
            //  cout<<lca<<" "<<tar<<" "<<f<<" "<<g<<" "<<koyta<<" "<<endl;
              koyta+=query_bin(lca,i-L[lca]);
               if(len[tar]>=i-L[tar]+1)koyta--;
              if(parentanse[lca]>=i-L[lca])koyta++;
              ans[i+i-L[lca]*2]=max(ans[i+i-L[lca]*2],koyta);

              int ko=query_bin(lca,i+1-L[lca]);
              if(parentanse[lca]>=i+1-L[lca])ko++;
              if(lo_bo(lca,i-L[lca])||parentanse[lca]==i-L[lca]);
              else ko--;
              ans[i+1+i-2*L[lca]]=max(ans[i+1+i-2*L[lca]],ko+1);
          }
          }
          toxic2[x].pb(c);

       }

    }
    for(int i=1;i<=n;i++)
    {

       if(parentanse[i]>-1)mylist[i].insert(mp(parentanse[i],P[i][0]));
       int c=mylist[i].size();
       set<pii>::iterator it;
       for(it=mylist[i].begin();it!=mylist[i].end();it++)
       {
           pii rs=*it;
          // if(rs.fs+rs.fs-1>dia)continue;
           ans[min(rs.fs+rs.fs-1,n)]=(ans[min(rs.fs+rs.fs-1,n)],c);
           c--;
       }

    }
    for(int i=n;i>=1;i--)
    {
       ans[i]=max(ans[i+1],ans[i]);
       if(i&1)ans[i]=max(ans[i],ans[i]);
    }
    for(int i=1;i<=n;i++)
    {
      ans[1]=max(ans[1],(int)vc[i].size()+1);
    }
    for(int i=1;i<=n;i++)
    {
      ans[i]=max(ans[i],1);
      if(i<=dia)ans[i]=max(ans[i],2);
      printf("%d ",ans[i]);
    }
}

/*
8
5 6
6 1
1 2
1 3
3 4
1 7
7 8

*/


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, mod;
const int maxN = 1e5 + 10;
int a[maxN];
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}
void check(int x, int d) {
    for (int j = 0; j <= n - 1; j++) {
        int who = sum(x, mult(j, d));
        int p = lower_bound(a, a + n, who) - a;
        if (p == n || a[p] != who) return;
    }
    cout << x << " " << d;
    exit(0);
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> mod >> n;
    int s1 = 0;
    int s2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s1 = sum(s1, a[i]);
        s2 = sum(s2, mult(a[i], a[i]));
    }
    sort(a, a + n);
    assert(mod >= n);
    if (mod == n) {
        cout << 0 << " " << 1;
        return 0;
    }
    if (n == 1) {
        cout << a[0] << " " << 0;
        return 0;
    }
    int val = (int)((1LL * n * (n - 1) / 2) % mod);
    val = pw(val, mod - 2);
    for (int x = 0; x < n; x++) {
        int his_val = mult(val, sub(s1, mult(a[x], n)));
        if (his_val == 0) continue;
        int R1 = (1LL * n * (n - 1) / 2) % mod;
        int R2 = (1LL * (n * (n - 1) * (2 * n - 1)) / 6) % mod;
        int gg = sum(mult(n, mult(a[x], a[x])), mult(2, mult(a[x], mult(R1, his_val))));
        gg = sum(gg, mult(his_val, mult(his_val, R2)));
        if (gg != s2) continue;
        check(a[x], his_val);
    }
    cout << -1;

    return 0;
}


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

typedef long long ll;
const int maxn=3e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];

int ppow(int x,int y,int M)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2,M);
    ret=ret*1ll*ret%M;
    if (y&1) ret=ret*1ll*x%M;
    return ret;
}

pii solve(vector<int> v,int N,int M)
{
    if (N==1) return mkp(v[0],1);
    set<int> s;
    for (int i=0;i<N;i++) s.insert(v[i]);
    sort(all(v));
    int X=abs(v[0]-v[1]),k=0;
    for (int i=0;i<N;i++)
    {
        auto now=lower_bound(all(v),(v[i]+X)%M);
        if ((now-v.begin()!=N)&&(*now)==(v[i]+X)%M) k++;
    }
    k=N-k;
    int d=X*1ll*ppow(k,M-2,M)%M;

    int cnt=0,att;
    for (int i=0;i<N;i++)
    {
        if (s.find((v[i]+d)%M)==s.end())
        {
            cnt++;
            att=v[i];
        }
    }
    if (cnt!=1) return mkp(-1,-1);
    else return mkp((att+0ll+M-(N-1)*1ll*d%M)*1ll%M,d);
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    if (n==1||n==m) return cout<<a[1]<<' '<<1<<endl,0;
    sort(a+1,a+n+1);

    pii ret;
    vector<int> v;
    if (2*n<m)
    {
        for (int i=1;i<=n;i++) v.pb(a[i]);
        ret=solve(v,n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<ret.F<<' '<<ret.S<<endl;
    }
    else
    {
        int now=1;
        for (int i=0;i<m;i++)
        {
            if (now>n||a[now]!=i)
            {
                v.pb(i);
            }
            else now++;
        }
        ret=solve(v,m-n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<(ret.F+0ll+(m-n)*1ll*ret.S)*1ll%m<<' '<<ret.S<<endl;
    }
}


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

typedef long long ll;
const int maxn=1e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];
set<int> s;

int check(int x)
{
    int cnt=0,att;
    for (int i:s)
    {
        if (s.find((i+x)%m)==s.end())
        {
            cnt++;
            att=i;
        }
    }
    if (cnt!=1) return 0;
    vector<int> v;
    v.pb(att);
    for (int i=1;i<=n-1;i++)
    {
        att=(att+m-x)%m;
        v.pb(att);
    }
    sort(all(v));
    for (int i=0;i<n;i++)
    {
        if (v[i]!=a[i+1]) return 0;
    }
    return att+30;
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i],s.insert(a[i]);
    sort(a+1,a+n+1);
    if (n==m) return cout<<0<<' '<<1<<endl,0;

    const int C=min(m-1,int(sqrt(m))+3);
    for (int i=1;i<=C;i++)
    {
        int ret=check(i);
        if (ret) return cout<<ret-30<<' '<<i<<endl,0;
    }
    for (int i=1;i<=C;i++)
    {
        int ret=check(a[1+i]-a[1]);
        if (ret) cout<<ret-30<<' '<<i<<endl,0;
    }
    cout<<-1<<endl;
}


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

typedef long long ll;
const int maxn=3e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];

int ppow(int x,int y,int M)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2,M);
    ret=ret*1ll*ret%M;
    if (y&1) ret=ret*1ll*x%M;
    return ret;
}

pii solve(vector<int> v,int N,int M)
{
    set<int> s;
    for (int i=0;i<N;i++) s.insert(v[i]);
    sort(all(v));
    int X=abs(v[0]-v[1]),k=0;
    for (int i=0;i<N;i++)
    {
        auto now=lower_bound(all(v),(v[i]+X)%M);
        if ((now-v.begin()!=N)&&(*now)==(v[i]+X)%M) k++;
    }
    k=N-k;
    int d=X*1ll*ppow(k,M-2,M)%M;

    int cnt=0,att;
    for (int i=0;i<N;i++)
    {
        if (s.find((v[i]+d)%M)==s.end())
        {
            cnt++;
            att=v[i];
        }
    }
    if (cnt!=1) return mkp(-1,-1);
    else return mkp((att+0ll+M-(N-1)*1ll*d%M)*1ll%M,d);
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    if (n==1||n==m) return cout<<a[1]<<' '<<1<<endl,0;
    sort(a+1,a+n+1);

    pii ret;
    vector<int> v;
    if (2*n<m)
    {
        for (int i=1;i<=n;i++) v.pb(a[i]);
        ret=solve(v,n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<ret.F<<' '<<ret.S<<endl;
    }
    else
    {
        int now=1;
        for (int i=0;i<m;i++)
        {
            if (now>n||a[now]!=i)
            {
                v.pb(i);
            }
            else now++;
        }
        ret=solve(v,m-n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<(ret.F+0ll+(m-n)*1ll*ret.S)*1ll%m<<' '<<ret.S<<endl;
    }
}


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

typedef long long ll;
const int maxn=3e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];

int ppow(int x,int y,int M)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2,M);
    ret=int(ret*1ll*ret%M);
    if (y&1) ret=int(ret*1ll*x%M);
    return ret;
}

pii solve(vector<int> v,int N,int M)
{
    set<int> s;
    for (int i=0;i<N;i++) s.insert(v[i]);
    sort(all(v));
    int X=abs(v[0]-v[1]),k=0;
    for (int i=0;i<N;i++)
    {
        auto now=lower_bound(all(v),(v[i]+X)%M);
        if ((now-v.begin()!=N)&&(*now)==(v[i]+X)%M) k++;
    }
    k=N-k;
    int d=int(X*1ll*ppow(k,M-2,M)%M);

    int cnt=0,att;
    for (int i=0;i<N;i++)
    {
        if (s.find((v[i]+d)%M)==s.end())
        {
            cnt++;
            att=v[i];
        }
    }
    if (cnt!=1) return mkp(-1,-1);
    else return mkp(int((att+0ll+M-(N-1)*1ll*d)*1ll%M),d);
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);

    pii ret;
    vector<int> v;
    if (2*n<m)
    {
        for (int i=1;i<=n;i++) v.pb(a[i]);
        ret=solve(v,n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<ret.F<<' '<<ret.S<<endl;
    }
    else
    {
        int now=1;
        for (int i=0;i<m;i++)
        {
            if (now>n||a[now]!=i)
            {
                v.pb(i);
            }
            else now++;
        }
        ret=solve(v,m-n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<(ret.F+0ll+(m-n)*1ll*ret.S)*1ll%m<<' '<<ret.S<<endl;
    }
}


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

typedef long long ll;
const int maxn=3e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];

int ppow(int x,int y,int M)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2,M);
    ret=int(ret*1ll*ret%M);
    if (y&1) ret=int(ret*1ll*x%M);
    return ret;
}

pii solve(vector<int> v,int N,int M)
{
    set<int> s;
    for (int i=0;i<N;i++) s.insert(v[i]);
    sort(all(v));
    int X=abs(v[0]-v[1]),k=0;
    for (int i=0;i<N;i++)
    {
        auto now=lower_bound(all(v),(v[i]+X)%M);
        if ((now-v.begin()!=N)&&(*now)==(v[i]+X)%M) k++;
    }
    k=N-k;
    int d=int(X*1ll*ppow(k,M-2,M)%M);

    int cnt=0,att;
    for (int i=0;i<N;i++)
    {
        if (s.find((v[i]+d)%M)==s.end())
        {
            cnt++;
            att=v[i];
        }
    }
    if (cnt!=1) return mkp(-1,-1);
    else return mkp(int((att+0ll+M-(N-1)*1ll*d)*1ll%M),d);
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    if (n==1) return cout<<a[1]<<' '<<0<<endl,0;
    sort(a+1,a+n+1);

    pii ret;
    vector<int> v;
    if (2*n<m)
    {
        for (int i=1;i<=n;i++) v.pb(a[i]);
        ret=solve(v,n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<ret.F<<' '<<ret.S<<endl;
    }
    else
    {
        int now=1;
        for (int i=0;i<m;i++)
        {
            if (now>n||a[now]!=i)
            {
                v.pb(i);
            }
            else now++;
        }
        ret=solve(v,m-n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<(ret.F+0ll+(m-n)*1ll*ret.S)*1ll%m<<' '<<ret.S<<endl;
    }
}


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

typedef long long ll;
const int maxn=3e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];

int ppow(int x,int y,int M)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2,M);
    ret=int(ret*1ll*ret%M);
    if (y&1) ret=int(ret*1ll*x%M);
    return ret;
}

pii solve(vector<int> v,int N,int M)
{
    set<int> s;
    for (int i=0;i<N;i++) s.insert(v[i]);
    sort(all(v));
    int X=abs(v[0]-v[1]),k=0;
    for (int i=0;i<N;i++)
    {
        auto now=lower_bound(all(v),(v[i]+X)%M);
        if ((now-v.begin()!=N)&&(*now)==(v[i]+X)%M) k++;
    }
    k=N-k;
    int d=int(X*1ll*ppow(k,M-2,M)%M);

    int cnt=0,att;
    for (int i=0;i<N;i++)
    {
        if (s.find((v[i]+d)%M)==s.end())
        {
            cnt++;
            att=v[i];
        }
    }
    if (cnt!=1) return mkp(-1,-1);
    else return mkp(int((att+0ll+M-(N-1)*1ll*d)*1ll%M),d);
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);

    pii ret;
    vector<int> v;
    if (2*n<m)
    {
        for (int i=1;i<=n;i++) v.pb(a[i]);
        ret=solve(v,n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<ret.F<<' '<<ret.S<<endl;
    }
    else
    {
        int now=1;
        for (int i=0;i<m;i++)
        {
            if (now>n||a[now]!=i)
            {
                v.pb(i);
            }
            else now++;
        }
        ret=solve(v,m-n,m);
        if (ret.F==-1) cout<<-1<<endl;
        else cout<<(ret.F+0ll+(m-n)*1ll*ret.S)*1ll%m<<' '<<ret.S<<endl;
    }
}


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

typedef long long ll;
const int maxn=1e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int m,n;
int a[maxn];
set<int> s;

int check(int x)
{
    int cnt=0,att;
    for (int i:s)
    {
        if (s.find((i+x)%m)==s.end())
        {
            cnt++;
            att=i;
        }
    }
    if (cnt!=1) return 0;
    vector<int> v;
    v.pb(att);
    for (int i=1;i<=n-1;i++)
    {
        att=(att+m-x)%m;
        v.pb(att);
    }
    sort(all(v));
    for (int i=0;i<n;i++)
    {
        if (v[i]!=a[i+1]) return 0;
    }
    return att+30;
}

int32_t main()
{
    IOS
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>a[i],s.insert(a[i]);
    sort(a+1,a+n+1);
    if (n==m) return cout<<0<<' '<<1<<endl,0;

    const int C=min(m-1,int(sqrt(m))+10);
    for (int i=1;i<=C;i++)
    {
        int ret=check(i);
        if (ret) return cout<<ret-30<<' '<<i<<endl,0;
    }
    for (int i=1;i<=C;i++)
    {
        int ret=check(a[1+i]-a[1]);
        if (ret) cout<<ret-30<<' '<<i<<endl,0;
    }
    cout<<-1<<endl;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100010;

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

pair<int, int> solve(int n) {
  a[n + 1] = -1;
  sort(a + 1, a + n + 1);
  int d = a[2] - a[1], cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      vis[i] = true;
      ++cnt;
      int cur = 1;
      int x = a[i];
      while (true) {
        if ((x += d) >= p)
          x -= p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      x = a[i];
      while (true) {
        if ((x -= d) < 0)
          x += p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      LOG("%d %d\n", (x + d) % p, cur);
    }
  d = d * (ll)inv(cnt, p) % p;
  int x = a[1], pans;
  while (true) {
    if ((x -= d) < 0)
      x += p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] != x)
      break;
  }
  pans = (x + d) % p;
  cnt = n - 1;
  x = pans;
  while (true) {
    if ((x += d) >= p)
      x -= p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] == x)
      --cnt;
    else
      break;
  }
  if (cnt == 0)
    return make_pair(pans, d);
  return make_pair(-1, -1);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1 || n == p) {
    printf("%d 1\n", a[1]);
  } else {
    pair<int, int> ans;
    if (n * 2 > p) {
      for (int i = 1; i <= n; ++i)
        vis[a[i]] = true;
      int cnt = 0;
      for (int i = 0; i < p; ++i)
        if (!vis[i])
          a[++cnt] = i;
      memset(vis, 0, sizeof(vis));
      ans = solve(p - n);
      ans.first = (ans.first - ans.second + p) % p;
      ans.second = p - ans.second;
    } else {
      ans = solve(n);
    }
    if (ans.first >= 0)
      printf("%d %d\n", ans.first, ans.second);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100010;

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1 || n == p) {
    printf("%d 1\n", a[1]);
  } else {
    a[n + 1] = -1;
    sort(a + 1, a + n + 1);
    int d = a[2] - a[1], cnt = 0;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        vis[i] = true;
        ++cnt;
        int x = a[i];
        while (true) {
          if ((x -= d) < 0)
            x += p;
          int pos = lower_bound(a + 1, a + n + 1, x) - a;
          if (a[pos] == x) {
            vis[pos] = true;
          } else
            break;
        }
        x = a[i];
        while (true) {
          if ((x += d) >= p)
            x -= p;
          int pos = lower_bound(a + 1, a + n + 1, x) - a;
          if (a[pos] == x) {
            vis[pos] = true;
          } else
            break;
        }
      }
    d = d * (ll)inv(cnt, p) % p;
    int x = a[1], pans;
    memset(vis, 0, sizeof(vis));
    while (true) {
      if ((x -= d) < 0)
        x += p;
      int pos = lower_bound(a + 1, a + n + 1, x) - a;
      if (a[pos] == x) {
        vis[pos] = true;
      } else
        break;
    }
    pans = (x + d) % p;
    cnt = n - 1;
    x = pans;
    while (true) {
      if ((x += d) >= p)
        x -= p;
      int pos = lower_bound(a + 1, a + n + 1, x) - a;
      if (a[pos] == x) {
        vis[pos] = true;
        --cnt;
      } else
        break;
    }
    if (cnt == 0)
      printf("%d %d\n", pans, d);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100010;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1 || n == p) {
    printf("%d 1\n", a[1]);
  } else {
    a[n + 1] = -1;
    sort(a + 1, a + n + 1);
    int d = a[2] - a[1], cnt = 0;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        vis[i] = true;
        ++cnt;
        int x = a[i];
        while (true) {
          if ((x -= d) < 0)
            x += p;
          int pos = lower_bound(a + 1, a + n + 1, x) - a;
          if (a[pos] == x) {
            vis[pos] = true;
          } else
            break;
        }
        x = a[i];
        while (true) {
          if ((x += d) >= p)
            x -= p;
          int pos = lower_bound(a + 1, a + n + 1, x) - a;
          if (a[pos] == x) {
            vis[pos] = true;
          } else
            break;
        }
      }
    d = d * (ll)inv(cnt, p) % p;
    int x = a[1], pans;
    memset(vis, 0, sizeof(vis));
    while (true) {
      if ((x -= d) < 0)
        x += p;
      int pos = lower_bound(a + 1, a + n + 1, x) - a;
      if (a[pos] == x) {
        vis[pos] = true;
      } else
        break;
    }
    pans = (x + d) % p;
    cnt = n - 1;
    x = pans;
    while (true) {
      if ((x += d) >= p)
        x -= p;
      int pos = lower_bound(a + 1, a + n + 1, x) - a;
      if (a[pos] == x) {
        vis[pos] = true;
        --cnt;
      } else
        break;
    }
    if (cnt == 0)
      printf("%d %d\n", pans, d);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010;

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

pair<int, int> solve(int n) {
  if (n == 1)
    return make_pair(a[1], 1);
  a[n + 1] = -1;
  sort(a + 1, a + n + 1);
  int d = a[2] - a[1], cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      vis[i] = true;
      ++cnt;
      int cur = 1;
      int x = a[i];
      while (true) {
        if ((x += d) >= p)
          x -= p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      x = a[i];
      while (true) {
        if ((x -= d) < 0)
          x += p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      LOG("%d %d\n", (x + d) % p, cur);
    }
  d = d * (ll)inv(cnt, p) % p;
  int x = a[1], pans;
  while (true) {
    if ((x -= d) < 0)
      x += p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] != x)
      break;
  }
  pans = (x + d) % p;
  cnt = n - 1;
  x = pans;
  while (true) {
    if ((x += d) >= p)
      x -= p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] == x)
      --cnt;
    else
      break;
  }
  if (cnt == 0)
    return make_pair(pans, d);
  return make_pair(-1, -1);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == p) {
    printf("%d 1\n", 0);
  } else {
    pair<int, int> ans;
    if (n * 2 > p) {
      for (int i = 1; i <= n; ++i)
        vis[a[i]] = true;
      int cnt = 0;
      for (int i = 0; i < p; ++i)
        if (!vis[i])
          a[++cnt] = i;
      memset(vis, 0, sizeof(vis));
      ans = solve(p - n);
      if (ans.first >= 0) {
        ans.first = (ans.first - ans.second + p) % p;
        ans.second = p - ans.second;
      }
    } else {
      ans = solve(n);
    }
    if (ans.first >= 0)
      printf("%d %d\n", ans.first, ans.second);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010;

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

pair<int, int> solve(int n) {
  a[n + 1] = -1;
  sort(a + 1, a + n + 1);
  int d = a[2] - a[1], cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      vis[i] = true;
      ++cnt;
      int cur = 1;
      int x = a[i];
      while (true) {
        if ((x += d) >= p)
          x -= p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      x = a[i];
      while (true) {
        if ((x -= d) < 0)
          x += p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      LOG("%d %d\n", (x + d) % p, cur);
    }
  d = d * (ll)inv(cnt, p) % p;
  int x = a[1], pans;
  while (true) {
    if ((x -= d) < 0)
      x += p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] != x)
      break;
  }
  pans = (x + d) % p;
  cnt = n - 1;
  x = pans;
  while (true) {
    if ((x += d) >= p)
      x -= p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] == x)
      --cnt;
    else
      break;
  }
  if (cnt == 0)
    return make_pair(pans, d);
  return make_pair(-1, -1);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1 || n == p) {
    printf("%d 1\n", a[1]);
  } else {
    pair<int, int> ans;
    if (n * 2 > p) {
      for (int i = 1; i <= n; ++i)
        vis[a[i]] = true;
      int cnt = 0;
      for (int i = 0; i < p; ++i)
        if (!vis[i])
          a[++cnt] = i;
      memset(vis, 0, sizeof(vis));
      ans = solve(p - n);
      if (ans.first >= 0) {
        ans.first = (ans.first - ans.second + p) % p;
        ans.second = p - ans.second;
      }
    } else {
      ans = solve(n);
    }
    if (ans.first >= 0)
      printf("%d %d\n", ans.first, ans.second);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100010;

void exGcd(int a, int b, int&x, int& y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a, int p) {
  int x, y;
  exGcd(a, p, x, y);
  if (x < 0)
    x += p;
  return x;
}

int n, p;
int a[N];
bool vis[N];

pair<int, int> solve(int n) {
  a[n + 1] = -1;
  sort(a + 1, a + n + 1);
  int d = a[2] - a[1], cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      vis[i] = true;
      ++cnt;
      int cur = 1;
      int x = a[i];
      while (true) {
        if ((x += d) >= p)
          x -= p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      x = a[i];
      while (true) {
        if ((x -= d) < 0)
          x += p;
        int pos = lower_bound(a + 1, a + n + 1, x) - a;
        if (a[pos] == x) {
          vis[pos] = true;
          ++cur;
        } else
          break;
      }
      LOG("%d %d\n", (x + d) % p, cur);
    }
  d = d * (ll)inv(cnt, p) % p;
  int x = a[1], pans;
  while (true) {
    if ((x -= d) < 0)
      x += p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] != x)
      break;
  }
  pans = (x + d) % p;
  cnt = n - 1;
  x = pans;
  while (true) {
    if ((x += d) >= p)
      x -= p;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    if (a[pos] == x)
      --cnt;
    else
      break;
  }
  if (cnt == 0)
    return make_pair(pans, d);
  return make_pair(-1, -1);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &p, &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1 || n == p) {
    printf("%d 1\n", a[1]);
  } else {
    pair<int, int> ans;
    if (n * 2 > p) {
      for (int i = 1; i <= n; ++i)
        vis[a[i]] = true;
      int cnt = 0;
      for (int i = 0; i < p; ++i)
        if (!vis[i])
          a[++cnt] = i;
      memset(vis, 0, sizeof(vis));
      ans = solve(p - n);
      if (ans.first >= 0) {
        ans.first = (ans.first - ans.second + p) % p;
        ans.second = p - ans.second;
      }
    } else {
      ans = solve(n);
    }
    if (ans.first >= 0)
      printf("%d %d\n", ans.first, ans.second);
    else
      puts("-1");
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  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;

void debug_out()
{
    cerr << '\n';
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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(b + 1, b + n + 1);
    sort(c + 1, c + 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;
    }
    //m > n
    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 ok = 0;
    if (n * 2 > m)
    {
        //complement
        set <int> st;
        for1(i, n)
        {
            st.emplace(a[i]);
        }
        n = 0;
        for0(i, m)
        {
            if (!st.count(i))
            {
                a[++n] = i;
            }
        }
        if (n == 1)
        {
            x = a[1], d = 1, ok = 1;
        }
        else
        {
            int idx = 0;
            while (ok == 0)
            {
                ok = Try(++idx);
            }
        }
        x = (x + n * d) % m;
    }
    else
    {
        int idx = 0;
        while (ok == 0)
        {
            ok = Try(++idx);
        }
    }
    if (ok == 1)
    {
        cout << x << ' ' << d;
    }
    else
    {
        cout << -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#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;

void debug_out()
{
    cerr << '\n';
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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(b + 1, b + n + 1);
    sort(c + 1, c + 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;
    }
    //m > n
    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 ok = 0;
    if (n * 2 > m)
    {
        //complement
        set <int> st;
        for1(i, n)
        {
            st.emplace(a[i]);
        }
        n = 0;
        for0(i, m)
        {
            if (!st.count(i))
            {
                a[++n] = i;
            }
        }
        int idx = 0;
        while (ok == 0)
        {
            ok = Try(++idx);
        }
        x = (x + n * d) % m;
    }
    else
    {
        int idx = 0;
        while (ok == 0)
        {
            ok = Try(++idx);
        }
    }
    if (ok == 1)
    {
        cout << x << ' ' << d;
    }
    else
    {
        cout << -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#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;

void debug_out()
{
    cerr << '\n';
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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(b + 1, b + n + 1);
    sort(c + 1, c + 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;
    }
    //m > n
    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 ok = 0;
    if (n * 2 > m)
    {
        //complement
        set <int> st;
        for1(i, n)
        {
            st.emplace(a[i]);
        }
        n = 0;
        for0(i, m)
        {
            if (!st.count(i))
            {
                a[++n] = i;
            }
        }
        int idx = 0;
        while (ok == 0)
        {
            ok = Try(++idx);
        }
        x = (x + n * d) % m;
    }
    if (ok == 1)
    {
        cout << x << ' ' << d;
    }
    else
    {
        cout << -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#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)
        {
            for (auto &p: mp)
            {
                a[++n] = p.fi;
            }
        }
        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 <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;
    }
    //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 <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;
    }
    //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 ok = 0, idx = 0;
    while (ok == 0)
    {
        ok = Try(++idx);
    }
    if (ok == 1)
    {
        cout << x << ' ' << d;
    }
    else
    {
        cout << -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#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;
    }
    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;

void debug_out()
{
    cerr << '\n';
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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(b + 1, b + n + 1);
    sort(c + 1, c + 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;
    }
    //m > n
    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;
                }
            }
        }
    }
    if (n * 2 > m)
    {
        //complement
        set <int> st;
        for1(i, n)
        {
            st.emplace(a[i]);
        }
        n = 0;
        for0(i, m)
        {
            if (!st.count(i))
            {
                a[++n] = i;
            }
        }
    }
    int ok = 0, idx = 0;
    while (ok == 0)
    {
        ok = Try(++idx);
    }
    if (ok == 1)
    {
        cout << x << ' ' << d;
    }
    else
    {
        cout << -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}