N, M = map(int, input().split())
S_C_list = [[int(_) for _ in input().split()] for i in range(M)]

ans = '0' * N
for i_s, i_c in S_C_list:
    if ans[i_s-1] == '0' or ans[i_s-1] == str(i_c):
        ans = ans[:i_s-1] + str(i_c) + ans[i_s:]
        continue

    ans = '-1'
    break

else:
    if N != 1 and ans[0] == '0':
        ans = '-1'

print(int(ans))