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

for k in range(m):
    if n != 1:
        break
    if l[k][1] != 0:
        break
else:
    print(0)
    exit()

for i in range(m):
    if l[i][0] == 1 and l[i][1] == 0:
        print(-1)
        break
    if ans[l[i][0]-1] != -1 and ans[l[i][0]-1] != l[i][1]:
        print(-1)
        break
    else:
        ans[l[i][0]-1] = l[i][1]
else:
    for j in range(n):
        if ans[j] == -1:
            ans[j] = 0

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