#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> val(n, 10);
  vector<pair<int, int>> posbox(m);
  for (int i = 0; i < m; ++i) {
    int pos, val;
    cin >> pos >> val;
    posbox[i].first = n - pos;
    posbox[i].second = val;
  }
  for (auto &i : posbox) {
    val[i.first] = min(i.second, val[i.first]);
  }
  if (val[n - 1] == 10 || val[n - 1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = n - 1; i >= 0; --i) {
    cout << (val[i] == 10 ? 0 : val[i]);
  }
  cout << endl;
  return 0;
}
