import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int, input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    # print(N)
    # print(M)
    # print(sc)
    if N == 1:
        for i in range(10):
            string_i = str(i)
            for s,c in sc:
                if s != 1:
                    print(-1)
                    return
                if str(c) != string_i:
                    break 
            else:
                print(i)
        print(-1)
    else:
        start = 10 ** (N-1)
        end = 10 ** (N)
        for i in range(start, end):
            string_i = str(i)
            # print(string_i)
            for s,c in sc:
                # print(string_i[s-1])
                if string_i[s-1] != str(c):
                    break 
            else:
                print(i)
                return
        print(-1)

if __name__ == "__main__":
    main()

