#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t n, m;
  cin >> n >> m;
  vector<long long> z(n, -1);
  for (size_t i = 0; i < m; ++i) {
    size_t s, c;
    cin >> s >> c;
    --s;
    if (z[s] >= 0 && z[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (z[s] == -1 || c < z[s]) z[s] = c;
  }
  if (n > 1) {
    if (z[0] == 0) cout << -1 << endl;
    if (z[0] < 0) z[0] = 1;
    for (size_t i = 1; i < n; ++i) {
      if (z[i] < 0) z[i] = 0;
    }
  } else if (z[0] == -1)
    z[0] = 0;
  for (size_t i = 0; i < n; ++i) cout << z[i];
  cout << endl;
  return 0;
}
