from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
lin = [0]*n
lis = [0]*n
for i,j in li:
    if lis[i-1] == 0:
        if i == 1 and j == 0:
            print(-1)
            exit()
        lin[i-1] = j
        lis[i-1] = 1
    else:
        if lin[i-1] != j:
            print(-1)
            exit()
print(''.join(map(str, lin)))