#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> terms(m, vector<int>(2));
  for (int j = 0; j < m; j++) {
    int s, c;
    cin >> s >> c;
    terms[j][0] = s;
    terms[j][1] = c;
  }
  int init = 0;
  bool check = false;
  if (n != 1) init = (int)pow(10, n - 1);
  int endi = (n == 1) ? 10 : init * 10;
  if (!m)
    cout << init << endl;
  else {
    for (int i = init; i < endi; i++) {
      vector<int> tmp(n);
      int ii = i;
      for (int k = 0; k < n; k++) {
        tmp[k] = ii % 10;
        ii /= 10;
      }
      reverse(tmp.begin(), tmp.end());
      for (int j = 0; j < m; j++) {
        if (tmp[terms[j][0] - 1] != terms[j][1]) break;
        if (j == m - 1) check = true;
      }
      if (check) {
        cout << i << endl;
        break;
      }
      if (i == (init * 10) - 1) cout << -1 << endl;
    }
  }
  return 0;
}
