import sys

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

s = [0] * m
c = [0] * m

for j in range(m):
    s[j], c[j] = list(map(int, input().split()))

for i in range(1, 1000):
    nx = i // 10
    result = [i % 10]
    keta =  1
    while nx:
        keta += 1
        result.append(nx % 10)
        nx //= 10
    
    if keta != n:
        continue
    result.reverse()
    
    flg = True
    for ix in range(m):
       if result[s[ix]-1] != c[ix]:
          flg = False

    if flg:
        print(i)
        sys.exit()
    
print(-1)