#include <bits/stdc++.h>
using namespace std;
int m, n, ans;
int main() {
  cin >> n >> m;
  std::vector<int> s(m);
  std::vector<char> c(m);
  for (size_t i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  string num(n, 'x');
  for (size_t i = 0; i < m; i++) {
    if (num.at(s.at(i) - 1) != 'x' && num.at(s.at(i) - 1) != c.at(i)) {
      ans = -1;
      break;
    } else {
      num.at(s.at(i) - 1) = c.at(i);
    }
  }
  if (num.at(0) == '0' && n != 1) {
    ans = -1;
  } else if (num.at(0) == 'x') {
    num.at(0) == 'x';
  }
  if (ans != -1) {
    for (size_t i = 1; i < n; i++) {
      if (num.at(i) == 'x') {
        num.at(i) = '0';
      }
    }
    cout << num << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
