#include<iostream>
#include<utility>
#include<vector>
int V[10000000000];
int main(){
    int N, M;
    bool flag=true;
    std::cin >> N >> M;
    std::fill(V, V+N, -1);
    for(int i=0; i<M; i++){
        int tmp1, tmp2;
        std::cin >> tmp1 >> tmp2;
        if(N-tmp1 <= N-1){
            if(V[N-tmp1] == -1){
                V[N-tmp1] = tmp2;
            }else{
                if(V[N-tmp1] != tmp2) flag = false;
            }
            
        }
    }
    if(V[N-1] > 0 && flag){
        for(int i=N-1; i>=0; i--){
            printf("%d", V[i]<0 ? 0:V[i]);
        }
        printf("\n");
    }else{
        printf("-1\n");
    }
}