import sys
n,m = (int(x) for x in input().split())
s = []
c = []
for i in range(m):
    s_i,c_i = (int(x) for x in input().split())
    s.append(s_i)
    c.append(c_i)
if n ==1:
  num =0
else:
  num = 10 ** (n-1)
flag = [0]*(n+1)
for i in range(m):
    if flag[s[i]] == 0:
        if s[i] == 1 and c[i] == 0:
            print("-1")
            sys.exit()
            
        else:
            if s[i] == 1:
                num += c[i]*(10**(n-s[i])) - (10**(n-1))
            else:
                num += c[i]*(10**(n-s[i]))
            flag[s[i]] =s[i]
    else:
        st = str(num)
        if int(st[-1 * (n-s[i]+1)]) != c[i]:
            print("-1")
            sys.exit()
            
print(num)
        
