N,M = map(int, input().split())
L = [-1]*N
ans = 0
for _ in range(M):
    s,c = map(int, input().split())
    if ans < 0:
        continue
    if L[s-1] >= 0 and L[s-1] != c:
        ans = -1
        continue
    if N > 1 and s == 1 and c == 0:
        ans = -1
        continue
    if L[s-1] == c:
        continue
    ans += c*10**(N-s)
    L[s-1] = c
print(ans)