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