import numpy as np
def getLine():
    return list(map(int, input().split()))
n,m = getLine()
s = np.full(m,-1)
c = np.full(m,10)
r = np.full(n,-1)
for i in range(m):
    a,b = getLine()
    if a in s:
        c[np.where(a == s)] = min(c[np.where(a == s)], b)
    else:
        s[i] = a
        c[i] = b
s = s[s != -1]
c = c[c != 10]
for a,b in zip(s,c):
    if a != -1:
        r[a-1] = b
if r[0] < 0 or (n > 1 and r[0] == 0):
    print('-1')
else:
    r[np.where(r == -1)] = 0
    r[np.where(r == 10)] = 0
    r = r.astype(str)
    print(int(''.join(r)))