1 const maxn=100000+10;maxm=1000000+10;
2 type node=record
3 from,go,next,w:longint;
4 end;
5 var e:array[0..maxm] of node;
6 mi,mx,n,m,x,y,i,ans1,ans2,tot:longint;
7 head,d:array[0..maxn] of longint;
8 v:array[0..maxn] of boolean;
9 circle:boolean;
10 function gcd(a,b:longint):longint;
11 begin
12 if b=0 then exit(a) else exit(gcd(b, a mod b));
13 end;
14
15 function min(x,y:longint):longint;
16 begin
17 if x<y then exit(x) else exit(y);
18 end;
19 function max(x,y:longint):longint;
20 begin
21 if x>y then exit(x) else exit(y);
22 end;
23
24 procedure insert(x,y,Z:longint);
25 begin
26 inc(tot);
27 with e[tot] do
28 begin
29 from:=x;go:=y;w:=z;next:=head[x];head[x]:=tot;
30 end;
31 end;
32 procedure init;
33 begin
34 readln(n,m);
35 for i:=1 to m do
36 begin
37 readln(x,y);
38 insert(x,y,1);insert(y,x,-1);
39 end;
40 end;
41 procedure dfs(x:longint);
42 var i,y:longint;
43 begin
44 v[x]:=true;
45 i:=head[x];
46 while i<>0 do
47 begin
48 y:=e[i].go;
49 if (v[y]) and (d[y]<>d[x]+e[i].w) then
50 begin
51 if circle then ans1:=gcd(ans1,abs(d[y]-(d[x]+e[i].w)))
52 else ans1:=abs(d[y]-(d[x]+e[i].w));
53 circle:=true;
54 end;
55 if (not(v[y])) then
56 begin
57 d[y]:=d[x]+e[i].w;
58 mi:=min(mi,d[y]);
59 mx:=max(mx,d[y]);
60 dfs(y);
61 end;
62 i:=e[i].next;
63 end;
64 end;
65
66 procedure main;
67 begin
68 circle:=false;
69 fillchar(v,sizeof(v),false);
70 fillchar(d,sizeof(d),false);
71 for i:=1 to n do
72 begin
73 if not(v[i]) then
74 begin
75 mi:=0;mx:=0;
76 dfs(i);
77 inc(ans2,mx-mi+1);
78 end;
79 end;
80 if not circle then
81 begin
82 if ans2<3 then write(-1,‘ ‘,-1)
83 else write(ans2,‘ ‘,3);
84 end
85 else
86 begin
87 if ans1<3 then write(-1,‘ ‘,-1)
88 else
89 begin
90 write(ans1,‘ ‘);
91 for i:=3 to ans1 do
92 if ans1 mod i=0 then break;
93 write(i);
94 end;
95 end;
96 end;
97
98
99 begin
100 assign(input,‘party.in‘);assign(output,‘party.out‘);
101 reset(input);rewrite(output);
102 init;
103 main;
104 close(input);close(output);
105 end.