n, m = map(int, input().split())
s, c = [], []

for _ in range(m):
    tmp1, tmp2 = map(int, input().split())
    s.append(tmp1)
    c.append(tmp2)

flag = True
for i in range(1, 1000):
    i = str(i)
    cnt = 0

    if len(i)<n:
        continue

    else:
        for ss, cc in zip(s, c):
            if ss>n:
                continue
            elif i[ss-1] == str(cc):
                cnt += 1
        if cnt==m:
            print(int(i))
            flag = False
            break

if flag:
    print(-1)