NM = input().split()
N = NM[0]
M= NM[1]
N = int(N)
M  = int(M)
S = []
C = []
for i in range(M):
    inp = input().split()
    inp = [int(i) for i in inp]
    S.append(inp[0])
    C.append(inp[1])


def step1(S,C,M,N):
    result = [False]*N
    for i in range(M):
        if result[S[i]-1] ==False :
            result[S[i]-1]= C[i]    
            pass
        if result[S[i]-1] == C[i]:
            pass
        else:
            return -1
    
    return result


def step2(S,C,M,N,result):
    if result[0] == 0:
        return -1
    if  result[0] == False :
        print(result[0])
        result[0] = 1
        return result

    return result

def step3(result):
    for i in range(len(result)):
        if result[i] == False:
            result[i] = 0
    
    return result

def check(S,C,M,N):
    result  = step1(S,C,M,N)
    if  result== -1:
        return -1
    if step2(S,C,M,N,result) == -1:
        return -1
    result = step3(result)

    result  = [str(i) for i in result ]
    result= ''.join(result)
    return result


print(check(S,C,M,N))
NM = input().split()
N = NM[0]
M= NM[1]
N = int(N)
M  = int(M)
S = []
C = []
for i in range(M):
    inp = input().split()
    inp = [int(i) for i in inp]
    S.append(inp[0])
    C.append(inp[1])


def step1(S,C,M,N):
    result = [None]*N
    for i in range(M):
        if result[S[i]-1] ==None :
            result[S[i]-1]= C[i]    
            pass
        if result[S[i]-1] == C[i]:
            pass
        else:
            return -1
    
    return result


def step2(S,C,M,N,result):
    if result[0] == 0:
        print('k')
        return -1
    if  result[0] == None :
        print(result[0])
        result[0] = 1
        return result

    return result

def step3(result):
    for i in range(len(result)):
        if result[i] == None:
            result[i] = 0
    
    return result

def check(S,C,M,N):
    result  = step1(S,C,M,N)
    if  result== -1:
        return -1
    if step2(S,C,M,N,result) == -1:
        return -1
    result = step3(result)

    result  = [str(i) for i in result ]
    result= ''.join(result)
    return result


print(check(S,C,M,N))
