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


def main():
    n, m = map(int, input().split())
    inf = float('inf')
    number = [inf] * n

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

        number[si] = min(number[si], ci)

    for index, num in enumerate(number):
        if num == inf:
            number[index] = 0

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

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


if __name__ == '__main__':
    main()
