n, m = map(int,input().split())
ans = 0
a = [-1]*n
for i in range(m):
  s, c = map(int,input().split())
  if a[s-1] in [-1, c]:
    a[s-1] = c
  else:
    ans = -1
    break
if a[0] == 0 and n > 1:
  ans = -1
if ans == 0 and a != [0]:
  ans += max(a[0],1)*10**(n-1)
  for i in range(1,n):
    ans += max(a[i],0)*10**(n-i-1)
print(ans)