#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p, d;
  cin >> n >> m;
  if (n == 1) {
    if (m == 0) {
      cout << 0 << '\n';
      return 0;
    }
    cin >> p >> d;
    cout << d << '\n';
    return 0;
  }
  vector<int> done(n, -1);
  bool possible = true;
  while (m--) {
    cin >> p >> d;
    if (p == 1 && d == 0) possible = false;
    if (done[p - 1] != -1) {
      if (d != done[p - 1]) {
        possible = false;
      }
    } else
      done[p - 1] = d;
  }
  if (possible == false)
    cout << -1 << '\n';
  else
    for (int x : done)
      if (x == -1)
        cout << 0;
      else
        cout << x;
  cout << '\n';
  return 0;
}
