import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,m = [int(i) for i in readline().split()]
sc = [[int(i) for i in readline().split()] for _ in range(m)]

ans = [0]*n

for s,c in sc:
    if ans[s-1] == 0:
        ans[s-1] = c
    elif ans[s-1] != c:
        print(-1)
        break
else:
    if ans[0] == 0:
        ans[0] = 1
    ans = sum([10**(n-i-1)*d for i,d in enumerate(ans)])
    print(ans)