n, m = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(n))
ans = ["0","0","0"]
for i in range(m):
    ans[(sc[i][0])-1] = str(sc[i][1])

ans2 = ''.join(ans)
if  n == 3 and ans[0] == 0:
    print("-1")
elif  n == 2 and ans[0] >= 0 and ans[1] == 0 :
    print("-1")
elif m == 0:
    print("-1")
else:
    print(ans2)   