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

#%%
ans = 0
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-1))*c

if not(n in s2c):
    ans += 10**(n-1)

print(ans)