import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(m)]

    def dfs(X):
        if len(X) == n:
            for s, c in query:
                if X[s - 1] != int(c):
                    break
            else:
                res = "".join(map(str, X))
                print(res)
                exit()
            return

        for i in range(0 if len(X) > 0 else 1, 10):
            X.append(i)
            dfs(X)
            X.pop()

    dfs([])
    print(-1)


if __name__ == '__main__':
    resolve()
