#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  //vector<vector<int>> data(m, vector<int>(2,0));
  vector<int> data(n, 0);
  vector<bool> flg(n, false);
  //int hud=0;
  //int ten=0;
  //int one=0;
  
  int x=0;
  int y=0;
  for(int i=0;i<m;i++){
    cin >> x >> y;
    if(flg.at(x-1)==false){
      data.at(x-1) = y;
      flg.at(x-1) = true;
    }else{
      data.at(x-1) = min(data.at(x-1),y);
    }
  }
  
  //先頭が0の場合を除外
  if(n=3){
    if(flg.at(0)==false || flg.at(1)==false || flg.at(2) ==false || (flg.at(0)==true && data.at(0)==0) || (flg.at(1)==true && data.at(0)==0)){
      cout << -1;
      return;
    }
  }else if(n=2){
    if(flg.at(0)==false || flg.at(1)==false  || (flg.at(0)==true && data.at(0)==0)){
      cout << -1;
      return;
    }
  }else{
    if(flg.at(0)==false){
      cout << -1;
      return;
    }
  }
  
  
  for(int j=0;j<m;j++){
    cout << data.at(j);
  }
}