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