N, M = map(int, input().split())
s = []
c = []
for _ in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)

for i in range(1000):
    cnt = 0
    for j in range(M):
        if (s[j] > N):
            break
        if len(str(i)) != N:
            break
        else:
            if (s[j] == 1):
                if (int(str(i)[0]) == c[j]):
                    cnt += 1
            elif(s[j] == N):
                if (int(str(i)[-1]) == c[j]):
                    cnt += 1
            else:
                if (int(str(i)[s[j] - 1:s[j]]) == c[j]):
                    cnt += 1
    if (cnt == N):
        print(i)
        exit()
    cnt = 0


print(-1)
