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 = a_list[1]

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

    ans[rank] = num

for_p = ['0']*m
for i in range(m):
    if judge[i] == 1:
        for_p[i] = str(ans[i])

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