#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    result = N * 10000

    if set(c) == {0} and N not in s:
        return print(-1)

    for num in range(1, (10 ** (N))):
        flag = True
        s_num = str(num).zfill(N)

        for j in range(M):
            if s_num[s[j] - 1] != str(c[j]):
                flag = False
                break
        if flag and num >= 0:

            result = min(result, int(num))

    if result != N * 10000:
        print(result)
    else:
        print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)


if __name__ == "__main__":
    main()
