
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact

N,M=acinput()

digit=[-1]*N
for i in range(M):
    s=acinput()
    if digit[s[0]-1] >= 0 and digit[s[0]-1]!=s[1]:
        print(-1)
        sys.exit()

    digit[s[0]-1]=s[1]

#print(digit)

if N==1 and digit[0]==0:
    print(0)
    sys.exit()

if digit[0]==0:
    print(-1)
    sys.exit()

if digit[0]==-1:
    digit[0]=1

for i in range(N):
    if digit[i]<0:
        digit[i]=0


print("".join(map(str,digit)))
