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


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

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

        number[si].append(ci)

    if n >= 2:
        if len(number[0]) == 0:
            print(-1)
            exit()
        elif len(number[0]) == 1 and number[0][0] == 0:
            print(-1)
            exit()

    ans = list()

    for index, element in enumerate(number):
        if len(element) == 0:
            number[index].append(0)

        if n >= 2 and 0 in number[0] and index == 0:
            ans.append(sorted(number[0])[1])
        else:
            ans.append(min(number[index]))

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

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


if __name__ == '__main__':
    main()
