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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> data(m, vector<int>(2));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m-i; j++) {
      if(data.at(i).at(0)==data.at(i+j).at(0) && data.at(i).at(1)!=data.at(i+j).at(1)){
      cout << -1 << endl;
      return 0;
      }
      if(n>1 && data.at(i).at(0)==n && data.at(i).at(1)==0){
      	cout << -1 << endl;
        return 0;
      }
    }
  }
  int one=0;
  if(n>1)
  int two=10;
  else
  int two =0;
  if(n>2)
  int thr=100;
  else
  int thr=0;
  for (int i = 0; i < m; i++) {
      if(data.at(i).at(0)==1)
      one = (data.at(i).at(1))*pow(10,n-1);
      if(data.at(i).at(0)==2)
      two = (data.at(i).at(1))*pow(10,n-2);
      if(data.at(i).at(0)==3)
      thr = (data.at(i).at(1));
  }
  cout << one+two+thr << endl;   			
}

