n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
 
for i in range(1000):
    s = str(i)
    if len(s) != n:
      continue
    if all(s[a - 1] == str(b) for a, b in sc):
        print(i)
        exit()
 
print(-1)