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

ans = [-1] * N

for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

if M == 0 and N != 1:
    ans[0] = 1
tmp = int(''.join((map(str, [int(str(a).replace('-1', '0')) for a in ans]))))
if N >= 2 and tmp == 0 and ans[0] == -1:
    ans[0] = 1

ans = [int(str(a).replace('-1', '0')) for a in ans]

res = ''.join((map(str, ans)))
if int(res) >= 0 and len(str(int(res))) == N:
    print(int(res))
else:
    print(-1)
