#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  int pos, x;
  bool ok = 1;
  while (m--) {
    cin >> pos >> x;
    pos--;
    if (!ok) {
      continue;
    }
    if (v[pos] != -1 && x != v[pos]) {
      ok = 0;
    } else {
      v[pos] = x;
    }
  }
  if (!ok) {
    cout << -1 << "\n";
    return;
  }
  if (n != 1 && v[0] <= 0) {
    cout << -1 << "\n";
    return;
  }
  for (auto &e : v) {
    if (e == -1) e = 0;
    cout << e;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed;
  cout << setprecision(0);
  solve();
  return 0;
}
