n, M = map(int, input().split())
m = {}

for i in range(M):
    s, c = map(int, input().split())
    # sc.append(list(map(int, input().split())))
    m[s] = c

# print(m)

def isValid(x):
    # print(x)
    if len(str(x)) != n:
        return False
    if len(str(x)) > n:
        print(-1)
        exit()

    # print(x)
    for i in range(n):
        val = int(str(x)[i])
        # print(i, val)
        if i+1 not in m:
            continue
        elif val != m[i+1]:
            return False
    return True

for i in range(10**(n+1)):
    if isValid(i):
        print(i)
        exit()

print(-1)