N, M = map(int, input().split())

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

for i in range(0, 1000):
    str_i = str(i)

    flag = True
    for s, c in S_C:
        if len(str_i) < s:
            flag = False
            break

        if str_i[s - 1] != str(c):
            flag = False
            break

    if flag:
        print(i)
        quit(0)

print(-1)
