#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> m;
  int n, q, a, b, flag = 1;
  cin >> n >> q;
  vector<int> s(n, 0);
  s.resize(n);
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    if (m[i]) {
      if (b == s[a - 1]) {
        s[a - 1] = b;
        m[a - 1] = 1;
      } else {
        flag = 0;
        break;
      }
    } else {
      if (a == 1 && b == 0 && n != 1) {
        cout << -1 << "\n";
        return 0;
      }
      s[a - 1] = b;
      m[a - 1] = 1;
    }
  }
  if (flag) {
    for (auto i : s) cout << i;
    cout << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}
