N, M = map(int, input().split())
ans = ['0'] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s-1] != '0' and ans[s-1] != str(c):
        print(-1)
        exit()
    ans[s-1] = str(c)
if N == 1 and all(a == '0' for a in ans):
    print(0)
elif 1 <= N <= 2:
    print(-1)
elif ans[0] == '0':
    print(-1)
else:
    print(''.join(ans))
