if __name__ == "__main__":
    n, m = map(int, input().split())
    sc = list()
    for i in range(m):
        sc.append(list(map(int, input().split())))

    for i in range(1000):
        s = str(i).zfill(3)
        if n == 3 and s[0] == '0':
            continue
        if n == 2 and s[1] == '0':
            continue
        flag = 0
        for j in range(m):
            if str(sc[j][1]) != s[sc[j][0]-1]:
                flag = 1
        if flag == 0:
            print(i)
            exit()

    print('-1')
