# n = int(input())
n, m = map(int,input().split())
# l = [[0 for _ in range(n)] for _ in range(n)]
l = [[],[],[]]
f = 1

for i in range(m):
    keta , num = map(int,input().split())
    l[keta-1].append(num)

# print(l)

for i in range(1010):
    si = str(i)
    if len(si) != n:
        continue
    for j in range(3):
        for k in l[j]:
            # print(keta, l)
            if si[j] == str(k):
                # print('OK')
                f = 0
            else:
                f = 1
                break
        if f:
            break
    if f == 0:
        print(si)
        exit()

print(-1)