n, m = map(int, input().split())
ans = [-1 for _ in range(n)]

for i in range(m):
    tmp = list(map(int, input().split()))
    if tmp[0] == 1 and tmp[1] == 0:
        print(-1)
        break
    if ans[tmp[0]-1] != -1 and ans[tmp[0]-1] != tmp[1]:
        print(-1)
        break
    else:
        ans[tmp[0]-1] = tmp[1]

else:
    for k in range(n):
        if ans[k] == -1:
            ans[k] = 0

    print(''.join(list(map(str,ans))))