n, m = map(int, input().split())
num = [0] * n
ans = []
for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] != 0 and num[s-1] != c:
        print(-1)
        exit()
    num[s-1] = c

if 1 < n and num[0] == 0:
    print(-1)
    exit()

for i in range(1000):
    ok = True
    string = str(i)
    if len(string) == n:
        for j in range(n):
            if len(string) <= j or len(num) <= j:
                continue
            elif num[j] == 0:
                continue
            elif string[j] != str(num[j]):
                ok = False
                break
        if ok:
            ans.append(i)
print(min(ans))