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

for i in range(m):
    l.append(list(map(int,input().split())))

# print(l)

for i in range(1000):
    si = str(i)
    for j in range(len(si)):
        keta.append(si[j])
    # print(keta)
    if len(si) == n:
        for k in range(m):
            # print(keta, l)
            if keta[l[k][0]-1] == str(l[k][1]):
                # print('OK')
                f = 0
            else:
                f = 1
                keta = []
                break
    else:
        f = 1
        keta = []
    if f:
        continue
    else:
        print(''.join(str(i)))
        break
else:
    print(-1)