n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans =[0]*n
flag = False
for i in range(m):
    for j in range(m):
        if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
            flag = True
            

for i in range(m):
    ans[sc[i][0]-1] = sc[i][1]

if flag or ans[0] == 0:
    print(-1)
else:
    print(ans[0]*100 + ans[1]*10 + ans[2])