# 標準入力
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 ss,cc in zip(s,c):
    if memo[ss-1] in [-1, cc]: memo[ss-1] = cc
    else: flag = 0 ; break

if memo[0]==-1 and m != 0: 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)
