import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    SC = [[int(x) for x in input().split()] for _ in range(N)]

    f = False
    for i in range(1000):
        if len(str(i)) != N:
            continue

        x = str(i)
        for s, c in SC:
            if int(x[s - 1]) != c:
                break
        else:
            f = True

        if f:
            print(i)
            return
    else:
        print(-1)


if __name__ == '__main__':
    main()

