n,m = map(int,input().split())
s = []
c = []
ans = [0]*n
for _ in range(m):
  st,ct = map(int,input().split())
  s.append(st)
  c.append(ct)

f = 1
for i in range(m):
  if s[i] == 1 and c[i] == 0:
    f = 0
    break
  if ans[s[i]-1] != 0 and ans[s[i]-1] != c[i]:
    f = 0
    break
  ans[s[i]-1] = c[i]
if f == 0:
  print(-1)
else:
  if ans[0] == 0:
    ans[0] = 1
  print(''.join(map(str,ans)))