#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
void V2(T &n, U &m) {
  for (long long int i = 0; i < n.size(); i++) {
    cin >> n[i] >> m[i];
  }
}
void Main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(m), c(m);
  V2(s, c);
  map<long long int, long long int> sre;
  for (long long int i = 0; i < (m); ++i) {
    s[i]--;
    if (sre.count(s[i])) {
      if (sre[s[i]] != c[i]) {
        cout << (-1) << endl;
        exit(0);
      }
    } else
      sre[s[i]] = c[i];
  }
  for (long long int i = 0; i < (n); ++i) {
    if (sre.count(i)) {
      if (i == 0 && sre[i] == 0) {
        cout << (-1) << endl;
        exit(0);
      }
      cout << sre[i];
    } else {
      if (i == 0) {
        cout << (-1) << endl;
        exit(0);
      } else {
        cout << 0;
      }
    }
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Main();
  return 0;
}
