# -*- coding: utf-8 -*-
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append([int(i) for i in input().split()])

for i in range(700, 710):
    tmp = str(i)
    if len(tmp) != n:
        continue
    else:
        flag = True
        for j in range(m):
            if tmp[sc[j][0] - 1] != str(sc[j][1]):
                #print(i, j, 'B')
                flag = False
        if flag:
            print(i)
            exit()
print(-1)
