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

from fractions import gcd
from math import ceil,floor
import collections

N,M=map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]

ans=0

if M==0:
    ans=-1
elif M==1:
    if A[0][0]==1:
        ans = A[0][1]*(10**(N-1))
    else:
        ans=-1
else:
    A.sort()
    if A[0][0] == 1:
        for i in range(0,M):
            if i==0:
                if A[i][0]==A[i+1][0]:
                    if A[i][1]!=A[i+1][1]:
                        ans=-1
                        break
                else:
                    ans = ans + A[i][1]*(10**(N-A[i][0]))
            elif i<M-1:
                if A[i][0]==A[i+1][0]:
                    if A[i][1]!=A[i+1][1]:
                        ans=-1
                        break
                    elif A[i-1][0]!=A[i][0]:
                        ans = ans + A[i][1]*(10**(N-A[i][0]))
            else:
                if A[i-1][0]!=A[i][0]:
                    ans = ans + A[i][1]*(10**(N-A[i][0]))
    else:
        ans=-1

print(ans)