n, m = map(int, input().split())
ans = [-1] * n
is_dead = False

for _ in range(m):
    i, kk = map(int, input().split())
    if ans[i-1] == -1 or ans[i-1] == kk:
        ans[i-1] = kk
    else:
        is_dead = True
        break

if is_dead:
    print(-1)
elif n != 1 and ans[0] == 0:
    print(-1)
else:
    ans_s = [] * n
    for s in ans:
        if s == -1:
            ans_s.append('0')
        else:
            ans_s.append(str(s))
    print(''.join(ans_s))