#inp = list(map(lambda x: int(x), input().split()))
#n,k = map(lambda x: int(x), input().split())
#p_n = list(map(lambda x:int(x),input().split()))

n,m = map(lambda x: int(x), input().split())
c =[]
for i in range(m):
    c.append(input().split())

first_chrs = []
for pair in c:
    first_chrs.append(pair[0])


first = set(first_chrs)


list_for_count = []


for chr in first:
    tmp = []
    for pair in c:
        if pair[0] == chr:
           tmp.append(pair[1])
           list_for_count.append(set(tmp))


flag = 0
for set in list_for_count:
    if len(set) != 1:
        flag = 1


if ["1","0"] in c:
    flag = 1


def create_num(list,n):
    hinagata = ""
    for i in range(n):
        hinagata = hinagata + "0"
    for pair in list:
        hinagata = hinagata[:int(pair[0])-1]+pair[1] + hinagata[int(pair[0]):]
    return hinagata


if flag == 1:
    print(-1)
else:
    ans = create_num(c,n)
    if ans[0] == "0":
        ans[0] = "1"
    print(int(create_num(c,n)))