def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = "-1"
    if N == 1:
        for i in range(10):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    elif N == 2:
        for i in range(10,100):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    else:
        for i in range(100,1000):
            if ans != "-1":
                break
            strnum = list(str(i))
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
                if j == M-1:
                    ans = i
                    break
    print(ans)

if __name__ == '__main__':
    main()