N, M = map(int, input().split(' '))
lis = [-1 for _ in range(N)]
not_exist = False
for _ in range(M):
    s, c = map(int, input().split(' '))
    if lis[s-1] == -1:
        lis[s-1] = c
    elif lis[s-1] > -1 and lis[s-1] != c:
        not_exist = True
if N > 1 and lis[0] == 0:
    print(-1)
elif not_exist:
    print(-1)
else:
    ans = 0
    dig = N-1
    for i in range(N):
        if lis[i] == -1 and i == 0:
            num = 1
        elif lis[i] == -1:
            num = 0
        else:
            num = lis[i]
        ans += (num * (10 ** dig))
        dig -= 1
    print(ans)