#include <bits/stdc++.h>
using namespace std;
template <class T>
int64_t sum(vector<T> a);
template <class T>
double ave(vector<T> a);
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v);
uint64_t gcd(int64_t a, int64_t b);
uint64_t lcm(int64_t a, int64_t b);
bool flagdebug = false;
int main() {
  flagdebug = true;
  int64_t n, m;
  cin >> n >> m;
  vector<pair<int64_t, int64_t>> a(m);
  vector<int64_t> p(n, -1);
  bool okflag = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first > n) {
      okflag = false;
      break;
    }
    if (p[a[i].first - 1] == -1) {
      p[a[i].first - 1] = a[i].second;
    } else {
      if (p[a[i].first - 1] != a[i].second) {
        okflag = false;
      }
    }
    if (okflag == false) break;
  }
  if (n > 1 && p[0] == 0) okflag = false;
  if (okflag == false) {
    cout << -1 << endl;
  } else {
    if (p[0] == -1) p[0] = 1;
    for (int i = 0; i < (int)(n); i++) {
      if (p[i] == -1) p[i] = 0;
      cout << p[i];
    }
    cout << endl;
  }
  return 0;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  s << "[\t";
  for (auto i = v.begin(); i < v.end() - 1; i++) {
    s << *i << "\t";
  }
  s << *(v.end() - 1) << "\t]\n";
  return s;
}
uint64_t gcd(int64_t a, int64_t b) {
  if (b != 0) {
    return gcd(b, a % b);
  }
  return a;
}
uint64_t lcm(int64_t a, int64_t b) { return a / gcd(a, b) * b; }
