N, M = list(map(int, input().split()))
SC = []
for i in range(M):
    s, c = list(map(int, input().split()))
    SC.append([s-1, c])

ans = [None] * N
r = True
for s, c in SC:
    if ans[s]:
        if ans[s] == c:
            pass
        else:
            r = False
    else:
        ans[s] = c

# print(ans, r)

if not r:
    print(-1)
elif N == 1 and ans[0] == 0:
    print(0)
elif ans[0] == 0:
    print(-1)
else:
    x = ''
    for i, ai in enumerate(ans):
        if i == 0 and ai is None:
            x += '1'
        elif ai is None:
            x += '0'
        else:
            x += str(ai)
    print(x)
        