n, m = map(int, input().split())

d={}

for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    elif s not in d:
        d[s] = c
    else:
        if d[s] != c:
            print(-1)
            exit()
if 1 not in d:
    d[1] = 1
for i in range(2, n+1):
    if i not in d:
        d[i] = 0
ans = 0
for i in range(1, n+1):
    ans += d[i] * pow(10, n-i)
print(ans)
