n, m = map(int, input().split())
q = [list(map(int, input().split())) for _ in range(m)]

ans = ['0']*n
judge = [0]*n

for i in range(m):
    a_list = q[i]
    rank = a_list[0] - 1
    num = str(a_list[1])

    if judge[rank] == 0:
        judge[rank] = 1
        ans[rank] = num
    else:
        if ans[rank] == num:
            continue
        else:
            print(-1)
            exit()


if ans[0] == '0' or ans[0] == 0:
    print(-1)
else:
    print(int(''.join(ans)))
