N, M = map(int, input().split(' '))

ans = [-1] * N

for m in range(M):
    s, c = map(int, input().split(' '))
    if s == 1 and c == 0:
        if N == 1:
            print(0)
        else:
            print(-1)
        exit(0)
    if ans[s - 1] != -1 and ans[s - 1] != c:
        print(-1)
        exit(0)
    ans[s - 1] = c


if ans[0] == -1:
    ans[0] = 1

if ans[0] == 0 and N != 1:
    print(-1)
    exit(0)

for i in range(1, N):
    if ans[i] == -1:
        ans[i] = 0

ANS = int(''.join(map(str, ans)))

print(ANS)