# 標準入力
n,m = map(int,input().split())
s,c = [],[]
for i in range(m):
    ss,cc = map(int,input().split())
    s.append(ss)
    c.append(cc)

# コンフリクト判定
memo = [-1 for i in range(n)]
flag = 1
for i in range(m):
    if memo[s[i]-1] in [-1, c[i]]: memo[s[i]-1] = c[i]
    else: flag = 0 ; break

if memo[0]==-1: memo[0]=1
if memo[0]==0 and n != 1: flag = 0
memo = [str(max(0,ele)) for ele in memo]

if flag: print("".join(memo))
else: print(-1)
