#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int N,M;
    cin >> N >> M;
    vector<int> si(M),ci(M);

    bool judge = false;

    rep(i,M){
        cin >> si.at(i);
        cin >> ci.at(i);

        if(si.at(i) == 1 && ci.at(i) != 0){
            judge = true;
        }else if(N == 1 && ci.at(0) == 0){
            judge = true;
        }
        
    }

    // 同じ桁に異なる値を記入していればNG
    // 最上に桁があればOK
    rep(i,M){
        rep(j,M){
          	if(i != j){
              if(si.at(i) == si.at(j) && ci.at(i) != ci.at(j)){
                    judge = false;
              }
            }
        }
    }

    // マップに置き換え
    map <int, int> output;
    if(judge == true){
        rep(i,M){
            output[si.at(i)] = ci.at(i);
        }
    }

    string outputstring;
    rep(i,N){
        if(output[i+1] != 0){
            outputstring += to_string(output[i+1]);
        }else{
            outputstring += "0";
        }
    }

    if(judge) cout << outputstring << endl;
    else cout << "-1" << endl;
    
}