nm=input().rstrip().split(" ")
n =int(nm[0])
m= int(nm[1])
lines=[]
import sys
for line in sys.stdin.readlines():
    nums=line.rstrip().split()
    lines.append(nums)
#print(lines)

linesd =list(map(list, set(map(tuple, lines))))
#print(linesd)
line1=[]
line2=[]
line3=[]
for (j,k) in enumerate(linesd):
    if j==1:
        line1.append(int(k[1]))
    elif j==2:
        line2.append(int(k[1]))
    elif j==3:
        line3.append(int(k[1]))
if len(line1)==0:
    line1.append(0)
elif len(line2)==0:
    line1.append(0)
elif len(line3)==0:
    line1.append(0)
#print(line1)
#print(line2)
#print(line3)
if len(line1)>1:
    print("-1")
elif len(line2)>1:
    print("-1")
elif len(line3)>1:
    print("-1")
elif n==1:
    print("line1[0]")
elif line1[0]==0:
    print("-1")
elif n==2:
    print("10*line1[0]+line2[0]")
elif n==3:
    print(100*line1[0]+10*line2[0]+line3[0])
        