n,m=map(int,input().split())
ans =[-1] * (n+1)
for _ in range(m):
    s,c = map(int,input().split())
    if ans[s] == -1 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()

for i in range(1,n+1):
    if ans[i] == -1:
        ans[i] = 0
if ans[1] == 0:
    print(-1)
else:
    print(ans[1]*100 + ans[2]*10+ans[3])