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

ans = ['-1'] * N

for i in range(M):
    if ans[sc[i][0]-1] == sc[i][1]:
        continue
    elif ans[sc[i][0]-1] == '-1':
        ans[sc[i][0]-1] = sc[i][1]
    else:
        print('-1')
        sys.exit()

if N >= 2:
    if ans[0] == '-1':
        ans[0] == 1
    elif ans[0] == 0:
        print('-1')
        sys.exit()

for i in range(N):
    if ans[i] == '-1':
        print(0)
        sys.exit()

real = 0
for i in ans:
    real = real * 10 + i

print(real)