#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
int main(void){
    
    int N, M;
    cin >> N >> M;
    int A[1000];
    int C[4] = { 10, 10, 10, 10} ;
    bool S[4] = {};
    for(int i = 0; i <= 999; i++){
        A[i] = 0;
    }
    
    if(M == 0 && N != 1){
        cout << -1 << endl;
        return 0;
    }
    
    for(int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;
        if(S[s-1] == true && c != C[s]){
            cout << -1 << endl;
            return 0;
        }
        if(s == 1 && c > 0){
            S[0] = true;
            C[1] = min(C[1], c);
        }
        if(s == 2 && c > 0){
            S[1] = true;
            C[2] = min(C[1], c);           
        }
        if(s == 3 && c > 0){
            S[2] = true;
            C[3] = min(C[2], c);            
        }
    }
    
    for(int i = 0; i < 3; i++){
        if(S[i] == false)
            C[i+1] = 0;
    }
    
    for(int i = 1; i <= N; i++){
        if(S[0] == 0 && N != 1){
            cout << -1 << endl;
            return 0;
        }
        cout << C[i];
    }cout << endl;
    
}
