import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


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


def main():
    N, M = MAP()
    sc = [LIST() for _ in range(M)]
    li = [-1 for _ in range(N)]

    for i, num in sc:
        i = i - 1
        if li[i] == -1 or li[i] == num:
            li[i] = num
        else:
            print(-1)
            exit()

    if li[0] == 0 or li[0] == -1:
        print(-1)
        exit()
        
    ans = 0
    for i in range(N):
        if li[i] == -1:
            li[i] = 0
        ans += li[i]*10**(N-i-1)

    print(ans)


if __name__ == '__main__':
    main()
