# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    numbers = [list() for _ in range(n)]

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        numbers[si].append(ci)

    ans = list()

    for index, element in enumerate(numbers):
        if n >= 2 and index != 0 and len(element) == 0:
            numbers[index].append(0)

        if n >= 2 and index == 0:
            digit = sorted(set(numbers[0]))

            if len(digit) == 0:
                print(-1)
                exit()
            elif len(digit) == 1 and 0 in digit:
                print(-1)
                exit()
            elif len(digit) >= 2 and 0 in digit:
                ans.append(digit[1])
                continue

        ans.append(min(numbers[index]))

    candidate = ''.join(map(str, ans))

    if len(str(int(candidate))) == len(candidate):
        print(candidate)
    else:
        print(-1)


if __name__ == '__main__':
    main()
