def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return
    
    # populate the digits with the constrained digit, if it exists,
    # or the minimum possible digit.  the min possible digit is
    # 1 if it's the leading digit, or zero otherwise
    digits = [d.pop() if d else 0 + int(i == 0) for i, d in enumerate(dcon)]

    if digit[0] == 0:
        print(-1)
    else:
        print(''.join(map(str, digits)))

main()
