
n, m = map(int, input().split())
s2c = {}

if n in s2c:
    ans = 0
else:
    ans = 10**(n-1)
for i in range(m):
    s, c = map(int, input().split())
    if s in s2c:
        if c != s2c[s]:
            print(-1)
            import sys
            sys.exit()
    else:
        s2c[s] = c
        ans += 10**s*c   
print(ans)

