#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<pair<int, int>> p;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b, a--;
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  vector<int> val(n, -1);
  int i = 0;
  bool flag = true;
  for (auto v : p) {
    if (v.first == i && val[i] == -1) {
      val[i] = v.second;
    }
    if (v.first == val[i] && val[i] != -1 && val[i] != v.second) {
      flag = false;
      break;
    }
    i++;
  }
  if (val[0] == -1 || val[0] == 0) flag = false;
  if (flag) {
    for (int i = 0; i < n; i++) {
      if (val[i] == -1) val[i] = 0;
      cout << val[i];
    }
  }
  if (!flag) cout << -1 << endl;
  return 0;
}
