N, M = map(int, input().split())
S = set()
C = ['0' for _ in range(M)]
ans = 0
for i in range(M):
    s, c = input().split()
    s = int(s)
    if s in S:
        if C[s-1] != c:
            ans = -1
            break
    else:
        S.add(s)
        C[s-1] = c

if ans == -1:
    print(-1)
elif N == 1 and C[0] == '0':
    print(0)
else:
    if 1 in S and C[0] == '0':
        print(-1)
    else:
        print(''.join(C))
