import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, M = [int(i) for i in input().strip().split()]
    conditions = [[int(i) for i in input().strip().split()] for _ in range(M)]
    table = [None] * N

    for condition in conditions:
        s, c = condition
        if table[s - 1] == c:
            continue
        elif table[s-1] != None:
            return -1
        else:
            table[s-1] = c
    ans = ""

    for n in table:
        if n == None:
            ans += "0"
        else:
            ans += str(n)
    ans = int(ans)
    if len(str(ans)) != N:
        return -1

    return ans


if __name__ == "__main__":
    print(main())
