import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]
    ret = [0] * N
    for sc in SC:
        s, c = sc
        if ret[s - 1] != 0 and ret[s - 1] != c:
            print(-1)
            break
        else:
            ret[s - 1] = c
    else:
        tmp = int("".join(map(str, ret)))
        if len(str(tmp)) == N:
            print(tmp)
        else:
            print(-1)


if __name__ == '__main__':
    main()
