import math
import itertools
import statistics
#n = int(input())
#n, d = list(input().split())
n, m = list(map(int, input().split()))
s = []
c = []
for i in range(m):
    x,y = [int(j) for j in input().split()]
    s.append(x)
    c.append(y)

keta_min = [10]*n
keta_max = [-1]*n
for i in range(m):
    if keta_min[s[i]-1] > c[i]:
        keta_min[s[i]-1]=c[i]
    if keta_max[s[i]-1] < c[i]:
        keta_max[s[i]-1]=c[i]


for i in range(n):
    if keta_min[i]!=keta_max[i]:
        if keta_min[i]==10 and keta_max[i]==-1:
            keta_min[i]=0
            keta_max[i]=0
        else:
            print(-1)
            exit()
    elif keta_min[0]==0 and keta_max[0]==0 and n!=1:
            print(-1)
            exit()


for i in range(n):
    print(keta_min[i], end="")

