#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  std::map<int, int> map;
  int key = 0;
  bool ok = false;
  for (int i = 1; i <= m; ++i) {
    int val = INT_MAX;
    cin >> key;
    cin >> val;
    if (map.count(key) && map[key] != val) {
      cout << -1 << endl;
      return 0;
    }
    if (map[key] == 0 || map[key] > val) {
      map[key] = val;
    }
    if (key >= n) {
      ok = true;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < m; ++i) {
    if (map[i] == 0) {
      map[i] = 0;
    }
  }
  if (map[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  priority_queue<pair<int, int>> pq;
  for (auto it = map.begin(); it != map.end(); it++) {
    pq.push(make_pair(it->first, it->second));
    std::cout << pq.top().second;
    pq.pop();
  }
  return 0;
}
