N, M = map(int, input().split())
ans = ['0'] * 3
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)
if N == 2:
    if ans[0] != '0' or ans[1] == '0':
        print(-1)
    else:
        print(''.join(ans)[1:])
if N == 3:
    if ans[0] == '0':
        print(-1)
    else:
        print(''.join(ans))
