import sys
def main():
    n, m = map(int, input().split())
    s = [tuple(map(int, input().split())) for _ in range(m)]
    s = set(s)
    len_s = len(s)
    if len_s != len(set([sc[0] for sc in s])):
        print(-1)
        sys.exit()
    lists = [0]*3
    for sc in s:
        lists[sc[0]-1
        ] = sc[1]
    r = int("".join(map(str,lists)))
    if n == 2 and r < 10:
        r = -1
    elif n == 3 and r < 100:
        r = -1
    print(r)
main()