def go():
    n, m = map(int, input().split())

    ret = ['0'] * n
    s= []
    c = []
    for _ in range(m):
        a, b = map(int, input().split())
        s.append(a)
        c.append(b)
        if ret[s[-1] - 1] == '0':
            ret[s[-1] - 1] = str(c[-1])
        elif ret[s[-1] - 1] != str(c[-1]):
            print(-1)
            return

    if len(ret) != 1 and ret[0] == '0':
        print(-1)
        return
    if len(ret) != 1 and ret[0] == '0':
        ret[0] = '1'
    print(''.join(ret))
    
go()