from collections import defaultdict
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
dc = defaultdict(int)
for i,j in a:
  if dc[i] and dc[i] != j+1:
    print(-1)
    exit()
  dc[i] = j+1
if dc[1] == 1:
  if n != 1:
    print(-1)
  else:
    print(0)
  exit()
ans = 0
for i,x in dc.items():
  if x != 0:
    ans += (x-1)*10**(n-i)
if ans < 10**(n-1):
  ans += 10**(n-1)
print(ans)