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()
    if m == 0 and n == 1:
        print(0)
        sys.exit()

    r = -1
    for i in range(10**n):
        i_s = str(i)
        i_s = i_s.zfill(n)
        flag = True
        if n == 3 and i_s[0] == 0:
            flag = False
        elif n == 2 and i_s[1] == 0:
            flag = False
        for sc in s:
            if i_s[sc[0]-1] != str(sc[1]):
                flag = False
        if flag:
            r = i
            break
    print(r)
main()