var
	N,M,X,i:Longint;
	flag:Boolean;
	s,c:Array[1..5]of Longint;
	t:Array[1..3]of Longint;
	sz,xx:Longint;
begin
	read(N,M);
	for i:=1 to M do begin
		read(s[i],c[i]);
		s[i]:=N+1-s[i];
	end;
	for X:=0 to 999 do begin
		xx:=X;
		if xx=0 then begin
			sz:=1;
			t[1]:=0;
		end else begin
			sz:=0;
			while xx>0 do begin
				inc(sz);
				t[sz]:=xx mod 10;
				xx:=xx div 10;
			end;
		end;
		flag:=True;
		for i:=1 to M do if(sz<s[i])or(t[s[i]]<>c[i])then begin
			flag:=False;
			break;
		end;
		if flag then begin
			writeln(X);
			exit;
		end;
	end;
	writeln(-1);
end.
