#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool exist = true;
  int ans = 0;
  vector<int> n_vec(n, 0);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (n_vec[s - 1] != 0 && n_vec[s - 1] != c) {
      exist = false;
      break;
    }
    if (s == 1 && c == 0) {
      exist = false;
      break;
    }
    n_vec[s - 1] = c;
  }
  if (exist == true) {
    for (int i = n_vec.size() - 1; i >= 0; --i) {
      if (i == n_vec.size() - 1 && n_vec[n_vec.size() - i - 1] == 0) {
        ans += 1 * (int)(pow(10, i));
        continue;
      }
      ans += n_vec[n_vec.size() - i - 1] * (int)(pow(10, i));
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
