#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    ac = 0
    placed = {}
    for i in s_c:
        s, c = i
        if s not in placed:
            placed[s] = c
            ac += (10 ** (n - s)) * c
        elif placed[s] != c:
            print(-1)
            return

    if n == 1 or (1 in placed and placed[1] != 0):
        print(ac)
    else:
        print(-1)


if __name__ == '__main__':
    main()
