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

if N == 0:
  N = 1

sc = [list(map(int, input().split())) for i in range(M)]

ans = ['x'] * N

for i in range(M):
  s = sc[i][0]
  c = sc[i][1]
  if s == 1 and c == 0:
    print(-1)
    exit()
  if ans[s-1] == 'x':
    ans[s-1] = str(c)
  else:
    if ans[s-1] != str(c):
      print(-1)
      exit()

for index, char in enumerate(ans):
  if char == 'x':
    ans[index] = '0'

print(int(''.join(ans)))
