[N, M] = list(map(int, input().split()))
lst_sc = [list(map(int, input().split())) for i in range(M)]

def main(N, M, lst_sc):
    
    numbers = [''] * N
    for sc in lst_sc:

        [s, c] = sc

        if s > N: return -1

        if numbers[s-1] == '':
            numbers[s-1] = str(c)
        elif numbers[s-1] == str(c):
            pass
        else:
            return -1

    if N > 1 and numbers[0] == '0': return -1
    if numbers[1] == '': numbers[1] = '0'
    if numbers[2] == '': numbers[2] = '0'
    
    answer = ''
    for i in range(N):
        answer += numbers[i]
    return int(answer)
    

if __name__ == "__main__":

    answer = main(N, M, lst_sc)
    print(answer)
