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

int main() {
  int keta,num;
  int tmp1, tmp2;
  
  cin >> keta >> num;
  
  map<int, int> m;
  vector<int> vec(10,0);
    
  for(int i = 0; i < num; i++){
    cin >> tmp1 >> tmp2;
    
    if(vec.at(tmp1) != 0 && m[tmp1] != tmp2){
      cout << -1;
      return 0;
    }
    
    vec.at(tmp1) += 1;
    m[tmp1] = tmp2;
  }
  
  for(int i = 1; i <= keta; i++){
    if(int i == 1 && m[i] == 0){
      cout << 1;
    }else{
      cout << m[i];
    }
  }
}
