n,m=map(int,input().split())
x=0
s=[list(map(int,input().split())) for i in range(m)]
s=sorted(s)
for i in range(m):
  if s[i][0]==1 and s[i][1]==0:
    x=-1

for i in range(m):
  for j in range(m):
    if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
      x=-1

a=[0]*n
for i in range(m):
  a[s[i][0]]=s[i][1]

for i in range(m):
  ans=a[i]*10**(n-i-1)
if a[0]==0:
  ans+=100
print(x,ans)