import sys

n, m = map(int, input().split())
num = [-1]*n

for i in range(m):
  s,c = map(int, input().split())
  if num[s-1] != -1 and num[s-1] != c:
      print(-1)
      sys.exit()
  num[s-1] = c
  
if n == 1 and num[0] == -1:
    num[0] = 0
elif n != 1 and num[0] == -1:
    num[0] = 1

num = ['0' if x == -1 else str(x) for x in num]

ans = ""
for i in num:
  ans += str(i)
ans = int(ans)

if len(''.join(num)) == n:
    print(ans)
else:
    print(-1)
