N, M = map(int, input().split())
leftNum = {}
intList = []
mark = 0

if M != 0:
    for i in range(M):
        fromLeft, num = map(int, input().split())
        if fromLeft in leftNum and num != leftNum[fromLeft]:
            mark = 1
        else:
            leftNum[fromLeft] = num
elif M == 0 and N != 1:
    for i in range(N):
        if i == 0:
            intList.append('1')
        else:
            intList.append('0')
else:
  intList.append('0')

for key in range(1, M + 1):
    #print(key)
    if key in leftNum:
        intList.append(str(leftNum[key]))
    else:
        intList.append('0')

stringNum = ''.join(intList)
intNum = int(stringNum)

#print(leftNum)
#print(intList)

if len(intList) == N:
    print(intNum)
else:
    mark = 1

if mark == 1:
    print(-1)
