N, M = map(int,input().split())
conditions = [list(map(int,input().split())) for i in range(M)]

for i in range(10**(N-1) ,10 ** N):
    isOk = False
    #print(i)
    for j,c in enumerate(conditions):
        s = str(i)
        #print(s)
        #print(c[0])
        #print(c[1])
        if c[0] > len(s):
            break
        if str(c[1]) != s[c[0]-1]:
            break
        if j == M -1:
            isOk = True

    if isOk:
        print(i)
        exit(0)

print(-1)
exit(0)