N, M = map(int, input().split())
num = [None] * (N)
ans = ''
for _ in range(M):
    x, y = map(int, input().split())
    if num[x-1] == None:
        num[x-1] = str(y)
    elif num[x-1] != str(y):
        ans = -1
        break

if ans == -1:
    print(ans)
elif len(num) >= 2 and num[0] == '0':
    print(-1)
elif len(num) >= 2 and num[0] == None:
    for i in range(N):
        if i == 0:
            ans += '1'
        else:
            if i == None:
                ans += '0'
            else:
                ans += i
    print(ans)
else:
    for i in num:
        if i == None:
            ans += '0'
        else:
            ans += i
    print(ans)