import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()

    m = N
    l = [10] * N
    for i in range(M):
        s, c = MAP()
        if l[s-1] == 10:
            l[s-1] = c
            m = s - 1 if s-1 < m else m
        else:
            if c != l[s-1]:
                print(-1)
                sys.exit()

    if N == 1 and l[0] == 0:
        print(0)
        sys.exit()

    ans = ""
    if not len(l) == N-m and l[m] == 0: ans += "1"
    for i in range(N-m):
        ans += str(l[i+m] % 10)

    flag = False
    for i in range(N-m):
        if not int(ans[i]) == 0:
            flag = True
        if not flag and int(ans[i]) == 0:
            print(-1)
            sys.exit()

    print(ans)


if __name__ == '__main__':
    main()
