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:
    print(-1)
    exit()
  dc[i] = j
if dc[1] == 0:
  print(-1)
  exit()
ans = 0
for i,x in dc.items():
  ans += x*10**(3-i)
print(ans)