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()


### FIXED CODE ###

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

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()
    if M == 0:
        if N == 1:
            print(0)
        elif N == 2:
            print(10)
        else:
            print(100)
        exit()
        
    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('1' + '0'*(m-1) + ans if len(ans) < N else ans)
    
    
if __name__ == '__main__':
    main()