1 #include<iostream>
2 #include<stdio.h>
3 #include<string.h>
4 #include<cmath>
5 using namespace std;
6 #define maxm 1000000
7 #define maxn 100001
8 struct node
9 {
10 int u,v,w,nex;
11 }edge[maxm<<1|1];
12 int head[maxn],cnt=1;
13 void add(int u,int v,int w)
14 {
15 edge[++cnt]=(node){u,v,w,head[u]};
16 head[u]=cnt;
17 }
18 int n,m,nn,mm;
19 bool book[maxn],flag[maxm<<1];
20 int d[maxn],ans;
21 int gcd(int a,int b)
22 {
23 return b?gcd(b,a%b):a;
24 }
25 void dfs1(int x)
26 {
27 book[x]=true;
28 for(int i=head[x];i;i=edge[i].nex)
29 {
30 if(!book[edge[i].v])
31 {
32 d[edge[i].v]=d[x]+edge[i].w;
33 dfs1(edge[i].v);
34 }
35 else
36 ans=gcd(ans,(int)abs(0.0+d[x]+edge[i].w-d[edge[i].v]));
37 }
38 }
39 void dfs2(int x)
40 {
41 nn=min(d[x],nn);
42 mm=max(d[x],mm);
43 book[x]=true;
44 for(int i=head[x];i;i=edge[i].nex)
45 if(!flag[i])
46 {
47 flag[i]=flag[i^1]=true;
48 d[edge[i].v]=d[x]+edge[i].w;
49 dfs2(edge[i].v);
50 }
51 }
52 int main()
53 {
54 int x,y;
55 scanf("%d%d",&n,&m);
56 for(int i=1;i<=m;i++)
57 {
58 scanf("%d%d",&x,&y);
59 add(x,y,1);
60 add(y,x,-1);
61 }
62 for(int i=1;i<=n;i++)
63 if(!book[i])
64 dfs1(i);
65 if(ans)
66 {
67 if(ans<3)
68 printf("%d %d",-1,-1);
69 else
70 {
71 for(x=3;x<=ans;x++)
72 if((ans%x)==0)
73 break;
74 printf("%d %d",ans,x);
75 }
76 return 0;
77 }
78 memset(book,0,sizeof(book));
79 for(int i=1;i<=n;i++)
80 if(!book[i])
81 {
82 nn=mm=d[i]=0;
83 dfs2(i);
84 ans+=mm-nn+1;
85 }
86 if(ans>=3)
87 printf("%d %d",ans,3);
88 else
89 printf("%d %d",-1,-1);
90 }