#include <iostream>
#include <string>

int main(void){
  int N,M;
  std::cin >> N;
  std::cin >> M;
  
  int s[M] = {};
  int c[M] = {};
  std::string ans;
  switch(N){
    case 1:
      ans = "0";
      break;
    case 2:
      ans = "00";
      break;
    case 3:
      ans = "000";
      break;
    default:
      ans = "";
  }
  bool isDic[N] = {};
  bool isAns = true;
  for(int i = 0;i < M;i++){
    std::cin >> s[i];
    std::cin >> c[i];
    char ch = '0' + c[i];
    
    if(isDic[s[i] - 1] && ans[s[i] - 1] != ch){
      isAns = false;
      break;
    }
    else if(s[i] == 1 && c[i] == 0){
      isAns = false;
      break;
    }
    isDic[s[i] - 1] = true;
    ans[s[i] - 1] = ch;
  }

  if(isAns){
    std::cout << ans << std::endl;
  }
  else{
   	std::cout << "-1" << std::endl; 
  } 
  
  return 0;
}