n,m = map(int,input().split())
data = [-1 for _ in range(n)]

for i in range(m):
    s,c = map(int,input().split())
    if s > n:
        print(-1)
        exit()
    elif s == 1 and c == 0:
        print(-1)
        exit()
    elif data[s-1] == -1 or data[s-1] == c:
        data[s-1] = c
    else:
        print(-1)
        exit()

ans = 0
for i in range(n):
    if data[i] == -1:
        ans += 1 * 10**(n-1-i)
    else:
        ans += data[i] * 10**(n-1-i)

print(ans)