N, M = map(int, input().split())
SC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[0])

ans = ['_'] * N
for s, c in SC:
    if s == 1 and c == 0:
        print(-1)
        quit()
    elif ans[s-1] != '_' and ans[s-1] != str(c):
        print(-1)
        quit()
    else:
        ans[s-1] = str(c)

for i, num in enumerate(ans):
    if N == 1 and ans[0] == '_':
        print(0)
        quit()
    elif i == 0 and ans[0] == '_':
        ans[0] = '1'
    elif num == '_':
        ans[i] = '0'

print(int(''.join(ans)))