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]*n
    for sc in s:
        lists[sc[0]-1] = sc[1]
        if n == 2 and sc[1] == 0:
            print(-1)
            break
        elif n == 3 and sc[1] == 0:
            print(-1)
            break
    if n == 3 and lists[0] == 0 and lists[1] == 0:
        print(-1)
        sys.exit()
    r = int("".join(map(str, lists)))
    print(r)
main()