N, M = map(int,input().split())
SC = [0]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != 0 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
    if s == 1:ans[0] = c
    if s == 2:ans[1] = c
    if s == 3:ans[2] = c
a = 0
for i in range(N):
    a += int(ans[i])*(10**(N-i-1))
if a <= 0:a = -1
print(a)