n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
y = [-1] * n
for i in range(m):
    if s[i][0] == 1 and s[i][1] == 0 and n != 1:
        print(-1)
        break
    elif y[s[i][0]-1] == -1 or y[s[i][0]-1] == s[i][1]:
        y[s[i][0]-1] = s[i][1]
    else:
        print(-1)
        break
else:
    if y[0] == -1:
        y[0] = 1
    z = ''
    for i in y:
        if i == -1:
            i = 0
        z += str(i)
    print(int(z))