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

int main() {
  int N;
  int M;
  cin >> N >> M;
  vector<vector<int>> A(M,vector<int>(2));
  for(int i = 0; i < M; i++) {
    cin >> A.at(i).at(0) >> A.at(i).at(1);
  }
  
  bool y = false;
  int z = std::pow(10, N);
  
  for(int j = 1; j < z; j++) {
    for(int k = 0; k < M; k++){
      int x = std::pow(10, A.at(k).at(0));
      if(j % x == A.at(k).at(0)) {
        y = true;
      }
      else {
        y = false;
        break;
      }
    }
      if (y == true) {
        cout << x << endl;
        break;
      }
      else if (j == z-1) {
        cout << -1 << endl;
        break;
      }
}