import numpy as np
n, m = map(int, input().split())
t = np.zeros((n+1),np.int64)
w = np.zeros((n+1),np.int64)
if n >= 2:
    t[n] = 1

for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if w[n+1-s] == 0:
        t[n+1-s] = c
        w[n+1-s] = 1
    else:
        if t[n+1-s] == c:
            pass
        else:
            print(-1)
            exit()

ans = 0
for i in range(1,n+1):
    ans += t[i] * 10**(i-1)
print(ans)
