#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long now() {
  return chrono::duration_cast<chrono::milliseconds>(
             chrono::system_clock::now().time_since_epoch())
      .count();
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  time_t start = now();
  long long n, m;
  cin >> n >> m;
  long long poss = true;
  vector<long long> num(n);
  vector<long long> marked(n);
  while (m--) {
    long long a, b;
    cin >> a >> b;
    if (n > 1 and a == 1 and b == 0) {
      poss = false;
      break;
    }
    if (marked[a - 1] and num[a - 1] != b) {
      poss = false;
      break;
    }
    num[a - 1] = b;
    marked[a - 1] = true;
  }
  if (poss) {
    for (long long i = 0; i < n; i++) {
      if (i == 0 and num[i] == 0) {
        cout << 1;
      } else {
        cout << num[i];
      }
    }
    cout << "\n";
  } else {
    cout << -1 << "\n";
  }
  cerr << "TIME => " << now() - start << "\n";
  return 0;
}
