n,m = map(int,input().split())
s = []
c = []
if n == 1:
    d = list(str(0))
else:
    d = list(str(10**(n-1)))

for i in range(m):
    tmps,tmpc = map(int,input().split())
    s.append(tmps)
    c.append(tmpc)

for i in range(0,m):
    if n == 1 and len(set(s)) >= 2:
        d = "-1" 
        break
    elif s[i]-1 == 0 and d[s[i]-1] != "1" and d[s[i]-1] != str(c[i]):
        d = "-1"
        break
    elif s[i]-1 > 0 and d[s[i]-1] != "0":
        d = "-1"
        break
    d[s[i]-1] = str(c[i])

t = ["0" for i in range(n)]
if d == t:
    print(-1)
else:
    print(''.join(d))