import numpy as np
from collections import Counter

N, M = [int(i) for i in input().split()]

s = np.ones(M)

c = np.ones(M)

for i in range(M):
    s[i], c[i] = [int(i) for i in input().split()]
    
ans = 0   
if i in range(M):
    for j in range(M):
        if s[i] == s[j]:
            if c[i] == c[j]:
                pass
            else:
                ans = -1
                break

          
          
a_100 = int(0)
a_10 = int(0)
a_1 = int(0)
flag_3 = 0
flag_2 = 0
for i in range(M):
    if (N-s[i]+1) == 1:
        a_1 = int(c[i])
    elif (N-s[i]+1) == 2:
        a_10 = int(c[i])
        flag_2 +=1
    elif (N-s[i]+1) == 3:
        a_100 = int(c[i])
        flag_3 +=1
aaa = str(a_100)+str(a_10)+str(a_1)
if (N==3) & (a_100 == 0) & (ans!=-1)&(flag_3 ==0):
    a_100 =1
    aaa = str(a_100)+str(a_10)+str(a_1)
    ans = int(''.join(map(str,aaa)))
elif (N==3) & (a_100 == 0) & (ans!=-1)&(flag_3 >0):
    ans =-1
elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 ==0)&(flag_3 ==0):
    a_10 = 1
    aaa = str(a_10)+str(a_1)
    ans = int(''.join(map(str,aaa)))
elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 >0)&(flag_3 >0):
	ans=-1
elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 ==0)&(flag_3 >0):
    a_10 = 1
    aaa = str(a_10)+str(a_1)
    ans = int(''.join(map(str,aaa)))
elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 >0)&(flag_3 ==0):
	ans=-1
elif (N==2) & (a_100 > 0)&(ans!=-1):
    ans =-1
elif (N==1) & ((a_100 > 0)| (a_10 > 0))  &(ans!=-1):
    ans =-1
    
else:
    aaa = str(a_100)+str(a_10)+str(a_1)

    ans = int(''.join(map(str,aaa)))
if i in range(M):
    for j in range(M):
        if s[i] == s[j]:
            if c[i] == c[j]:
                pass
            else:
                ans = -1
                break    
print(ans) 
    
    
        


### FIXED CODE ###

import numpy as np
from collections import Counter

N, M = [int(i) for i in input().split()]

s = np.ones(M)

c = np.ones(M)
if M>0:
    for i in range(M):
        s[i], c[i] = [int(i) for i in input().split()]
    
    ans = 0   
    if i in range(M):
        for j in range(M):
            if s[i] == s[j]:
                if c[i] == c[j]:
                    pass
                else:
                    ans = -1
                    break

          
          
    a_100 = int(0)
    a_10 = int(0)
    a_1 = int(0)
    flag_3 = 0
    flag_2 = 0
    for i in range(M):
        if (N-s[i]+1) == 1:
            a_1 = int(c[i])
        elif (N-s[i]+1) == 2:
            a_10 = int(c[i])
            flag_2 +=1
        elif (N-s[i]+1) == 3:
            a_100 = int(c[i])
            flag_3 +=1
    aaa = str(a_100)+str(a_10)+str(a_1)
    if (N==3) & (a_100 == 0) & (ans!=-1)&(flag_3 ==0):
        a_100 =1
        aaa = str(a_100)+str(a_10)+str(a_1)
        ans = int(''.join(map(str,aaa)))
    elif (N==3) & (a_100 == 0) & (ans!=-1)&(flag_3 >0):
        ans =-1
    elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 ==0)&(flag_3 ==0):
        a_10 = 1
        aaa = str(a_10)+str(a_1)
        ans = int(''.join(map(str,aaa)))
    elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 >0)&(flag_3 >0):
    	ans=-1
    elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 ==0)&(flag_3 >0):
        a_10 = 1
        aaa = str(a_10)+str(a_1)
        ans = int(''.join(map(str,aaa)))
    elif (N==2) & (a_100 == 0)& (a_10 == 0)&(ans!=-1)&(flag_2 >0)&(flag_3 ==0):
    	ans=-1
    elif (N==2) & (a_100 > 0)&(ans!=-1):
        ans =-1
    elif (N==1) & ((a_100 > 0)| (a_10 > 0))  &(ans!=-1):
        ans =-1
    
    else:
        aaa = str(a_100)+str(a_10)+str(a_1)

        ans = int(''.join(map(str,aaa)))
    if i in range(M):
        for j in range(M):
            if s[i] == s[j]:
                if c[i] == c[j]:
                    pass
                else:
                    ans = -1
                    break
if M ==0:
    if N ==1:
        ans =0
    elif N ==2:
        ans = 10
    elif N==3:
        ans =100
print(ans)