N, M = map(int, input().split())
S = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
    S[i], C[i] = list(map(int, input().split()))

if N == 1:
    if M == 0:
        print(0)
    else:
        if set(C) == 1:
            print(C[0])
        else:
            print(-1)
else:
    flg = [False for i in range(N)]
    ans = [1]
    for i in range(N - 1):
        ans.append(0)

    for s, c in zip(S, C):
        if s - 1 == 0 and c == 0:
            print(-1)
            break
        elif flg[s - 1] == True and c != ans[s - 1]:
            print(-1)
            break
        else:
            flg[s - 1] = True
            ans[s - 1] = c
    else:
        print(''.join([str(a) for a in ans]))