N, M = map(int, input().split())
n = [0 for i in range(N)]
pair = [list(map(int, input().split())) for i in range(M)]

pair = sorted(pair)

old_pair = [0, 0]

ok = True

for i in range(M):
    if pair[i][0] == old_pair[0] and pair[i][1] != old_pair[1]:
        ok = False
        break
    elif pair[i][0] != old_pair[0]:
        #print(pair[i][0])
        old_pair = pair[i]
        n[pair[i][0] - 1] = pair[i][1]

if n == [0]:
    print(0)
elif not ok:
    print(-1)
else:
    if n[0] == 0:
        print(1, end='')
    else:
        print(n[0], end='')
    for i in range(1, N):
        print(n[i], end='')
    print()