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

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