
if __name__ == '__main__':
    n, m = [int(i) for i in input().split()]

    d = {}
    for i in range(1, n + 1):
        d[i] = 0

    result = -1
    for i in range(m):
        s, c = [int(i) for i in input().split()]
        
        if d[s] != 0:
            result = -1
            break
        d[s] = c

    tmp = ""
    for i in sorted(d.keys()):
        tmp += str(d[i])

    if tmp != str(int(tmp)):
        result = -1
    else:
        result = int(tmp)
    
    print(result)
