#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> mp;
  int res = 0;
  for (int i = 0; i < m; ++i) {
    int t1, t2;
    cin >> t1 >> t2;
    if (n > 1 && t1 == 1 && t2 == 0) {
      res = -1;
      break;
    }
    auto itr = mp.find(t1);
    if (itr != mp.end()) {
      if (itr->second != t2) {
        res = -1;
        break;
      }
    } else {
      mp[t1] = t2;
    }
  }
  if (res == -1) {
    cout << res << endl;
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    auto itr = mp.find(i);
    if (itr != mp.end()) {
      res += itr->second * pow(10, n - i);
    }
  }
  if (res < pow(10, n - 1)) {
    res += pow(10, n - 1);
  }
  cout << res << endl;
  return 0;
}
