#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 = 1;
  for (int l = 0; l < N; l++) {
    z *= 10;
  }
  for (int j = 1; j < z; j++) {
    for (int k = 0; k < M; k++) {
      int x = 1;
      for (int l = 0; l < A.at(k).at(0); l++) {
        x *= 10;
      }
      if (j % x == A.at(k).at(1)) {
        y = true;
      } else {
        y = false;
        break;
      }
    }
    if (y == true) {
      cout << j << endl;
      break;
    } else if (j == z - 1) {
      cout << -1 << endl;
      break;
    }
  }
}
