N, M = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(M)]
ans = [-1] *N
for k in range(M):
    if ans[num[k][0] -1] == -1 or ans[num[k][0] -1] == num[k][1]:
        ans[num[k][0] -1] = num[k][1]
    else:
        ans[0] = 0
        break

if ans[0] == 0:
    print(-1)
else:
    ans = [1 if a == -1 else a for a in ans]
    print(''.join(map(str,ans)))