n, m = tuple([int(i) for i in input().strip().split(" ")])

def pow10(n):
    if n == 0:
        return 0
    r = 1
    for i in range(n):
        r = r * 10
    return r

if m == 0:
    print(pow10(n-1))
    import sys
    sys.exit(0)

d = {}

value = [0 for i in range(n)]
st = set()

for i in range(m):
    s, c = tuple([int(i) for i in input().strip().split(" ")])
    if s-1 in st and value[s-1] != c:
        print(-1)
        import sys
        sys.exit(0)
    value[s-1] = c
    st.add(s-1)

if len(value) > 1 and value[0] == 0:
    print(-1)
    import sys
    sys.exit(0)

print(int("".join([str(v) for v in value])))
