N, M = map(int,input().split())
s = [None]*M
c = [None]*M
for i in range(M):
    s[i], c[i] = map(int,input().split())
for n in range(10**(N-1), 10**N):
    st = str(n)
    f = True
    for i in range(M):
        if st[s[i]-1] != str(c[i]):
            f = False
            break
    if f:
        print(n)
        exit(0)
print(-1)
