# 標準入力
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+1)]
flag = 1
for i in range(m):
    if memo[s[i]] in [-1, c[i]]: memo[s[i]] = c[i]
    else: flag = 0 ; break

if memo[1]==-1: memo[1]=1
if memo[1]==0 : flag = 0
memo = [str(ele) for ele in memo]
memo.pop(0)

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