from collections import defaultdict


def main():
    flag_imp = 0
    n, m = map(int, input().split())
    conds = list(set([input() for i in range(m)]))
    conds_dict = defaultdict(list)
    for c in conds:

        conds_dict[int(c.split()[0])].append(c.split()[1])
 
    if max(list(map(len, conds_dict.values()))) > 1:
        flag_imp += 1
    else:
        try:
            first_digit = conds_dict[1][0]
        except IndexError:
            if n == 1:
                first_digit = "0"
            else:
                flag_imp += 1
        try:
            seond_digit = conds_dict[2][0]
        except IndexError:
            seond_digit = "0"

        try:
            third_digit = conds_dict[3][0]
        except IndexError:
            third_digit = "0"
           
    if flag_imp:
        print(-1)
    elif n > 1 and first_digit == "0":
        print(-1)
    else:
        if n == 1:
            print(first_digit)
        elif n == 2:
            print(first_digit + seond_digit)
        else:
            print(first_digit + seond_digit + third_digit)


if __name__ == "__main__":
    main()
