import math
from functools import reduce

def is_valid(N, s):
    # str_num = int(s)
    # if str_num == 0:
    #     return N == 1
    # return int(math.log10(str_num)) + 1 == N

    if len(s) == 1:
        return N == 1

    if len(s) == 2:
        return s[0] != "0"

    return s[0] != "0"

def make_num(N, digit_option):
    n_str = [""] * N
    for i, d in enumerate(digit_option):
        if len(d) == 0:
            n_str[i] = "0"
        else:
            n_str[i] = str(d[0])

    return n_str

def main():
    N, M = map(int, input().split())

    digit_option = [ set([]) for i in range(N) ]
    for i in range(M):
        s, c = map(int, input().split())
        s -= 1
        digit_option[s].add(c)

    for i, d in enumerate(digit_option):
        if len(d) > 1:
            print(-1)
            return
        digit_option[i] = sorted(d)

    n_str = make_num(N, digit_option)
    n_str = reduce(lambda s1, s2: s1 + s2, n_str)
    if is_valid(N, n_str):
        print(int(n_str))
    else:
        print(-1)

main()
