import sys
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(1,10**n):
    s = str(i).zfill(3)
    c = 0
    for i in range(m):
        if sc[i] == [1,0]:
            print(-1)
            sys.exit()
            
        if s[sc[i][0]-1] == str(sc[i][1]):
            c += 1
    
    if c == m:
        print(s)
        sys.exit()

print(-1)
    