N, M = map(int, input().split())
ans = ['-1'] * N

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        ans = -1
        print(ans)
        exit()

for i in range(N):
    if ans[i] == '-1':
        ans[i] = '0'
    if ans[0] == '0':
        ans = -1
        print(ans)
        exit()

print(''.join(ans))