#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    num = []
    for _ in range(N):
        num.append(-1)

    for i, j in zip(s, c):
        if num[i-1] < 0:
            num[i-1] = j
        elif num[i-1] == j:
            pass
        else:
            print(-1)
            return

    if num[0] == 0:
        if N == 1:
            print(0)
            return
        else:
            print(-1)
            return

    ret = []
    for i in range(N):
        if num[i] >= 0:
            ret.append(num[i])
        else:
            if i == 0:
                ret.append(1)
            else:
                ret.append(0)

    num = 0
    for i in range(N):
        num += ret[i] * 10 ** (N - i - 1)
    print(num)


# 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()
