import numpy as np
n,m= map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
y=10**(n-1)
y=str(y)
yy=np.zeros(n)
z=0
yyy=''
#print(y[1])
for i in range(n):
    if l[i][0]==1&l[i][1]==0:
        z=-1
    if y[int(l[i][0]-1)]!=str(l[i][1]):
        if yy[int(l[i][0]-1)]==0:
            y = list(y)
            y[int(l[i][0]-1)]=str(l[i][1])
            "".join(y)
        else:
            z=-1
    
    yy[int(l[i][0]-1)]=1
if z==0:
    for i in range(n):
        yyy+=y[i]
    print(int(yyy))
    
else:
    print(z)
