import sys
n, m = map(int, input().split())
s = []
c = []
for _ in range(m):
    s_, c_ = map(int, input().split())
    s.append(s_)
    c.append(c_)
res = [-1]*n
for i in range(m):
    for j in range(n):
        if s[i] == (j+1):
            if res[j] == -1 or res[j] == c[i]:
                res[j] = c[i]
            else:
                print(-1)
                sys.exit()
if res[0] == 0 and n > 1:
    print(-1)
    sys.exit()
ans = 0
if res[0] == -1:
    ans += 100
for i in range(n):
    if res[i] != -1:
        ans += res[i]*((10)**(n-i-1))
print(ans)