#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(100);
  vector<int> c(100);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if ((s.at(i) == s.at(j) && c.at(i) != c.at(j)) ||
          s.at(i) == 1 && c.at(i) == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  int num = 0;
  for (int i = 0; i < m; i++) {
    num += c.at(i) * pow(10, n - s.at(i));
  }
  if (num < pow(10, n - 1)) {
    num += pow(10, n - 1);
  }
  cout << num;
  return 0;
}
