N, M = map(int, input().split())
s = []
c = []
check = [-1 for _ in range(N)]
muri = False
for _ in range(M):
    tmp = list(map(int, input().split()))
    s.append(tmp[0])
    c.append(tmp[1])
 
result = [0 for _ in range(N)]
 
for idx, S in enumerate(s):
    if check[S-1] < 0:
        result[S-1] = str(c[idx])
        check[S-1] = c[idx]
        if (S == 1) and c[idx] == 0:
            if N != 1:
                muri = True
                break
    else:
        if check[S-1] != c[idx]:
            muri = True
            break
if result[0] == 0:
    result[0] = 1
a = ''
reigai = True
if N==1 and M==0:
    reigai = True
for i in result:
    a += str(i)
if muri:
    print(-1)
else:
    if reigai:
        print(0)
    else:
        print(int(a))