n,m = [int(v) for v in input().split()]
sc = [[int(v) for v in input().split()] for _ in range(m)]

ans = [-1 for _ in range(n+1)]
flag = True

for (s,c) in sc:
    if s > n: flag = False
    elif ans[s] != -1 and ans[s] != c: flag = False
    else: ans[s] = c

if ans[1] == -1: ans[1] = 1
elif ans[1] == 0: flag = False


if flag:
    for v in ans[1:]:
        if v == -1:
            print(0,end='')
        else:
            print(v,end='')
else:
    print(-1)
