import sys
n, m = map(int, input().split())
S = [0] * m
C = [0] * m
tmp = [0] * n

for i in range(m):
    S[i], C[i] = map(int, input().split())

for s, c in zip(S, C):
    if tmp[s-1] == 0:
        tmp[s-1] = c
    elif tmp[s-1] != c:
        print(-1)
        sys.exit()

ans = 0
for i, a in enumerate(tmp[::-1]):
    ans += a*10**(i)    

if (n>=2) & (ans < 10**(n-1)):
    print(-1)
    sys.exit()
    
print(ans)