N, M = map(int, input().split())

flag = 0
x = [-1] * N
for m in range(M):
  s, c = map(int, input().split())
  if (x[s-1] != -1) & (x[s-1] != c):
    #print("{} {}".format(s,c))
    flag = 1
    break
  else:
    x[s-1] = c
#print(x)
    
ans = 0
for n in range(N):
  if x[n] != -1:
    ans += 10**(N-n-1) * x[n]
#print(ans)
    
if (ans >= 10**(N-1)) & (flag == 0):
  print(ans)
else:
  print(-1)