#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<pair<int, int> > p;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    p.insert(pair<int, int>(s, c));
  }
  string ans = string(n, '0');
  s = 0;
  bool ok = true;
  if (p.begin()->first == 1 && p.begin()->second == 0) ok = false;
  auto tmp = --p.end();
  if (tmp->first > n) ok = false;
  if (ok) {
    for (auto itr = p.begin(); itr != p.end(); ++itr) {
      if (itr->first == s) {
        ok = false;
        break;
      }
      s = itr->first;
      ans[itr->first - 1] = *(to_string(itr->second).c_str());
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
