import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)

ans = np.full(N+1, -1)
for i in range(M):
  if((ans[s[i]]==-1)or(ans[s[i]]==c[i])):
    ans[s[i]] = c[i]
  else:
    print(-1)
    sys.exit()
ans = np.where(ans==-1, 0, ans)
if(ans[1]==0):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))