#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  if (n == 0) {
    return 1;
  } else {
    return n * factorial(n - 1);
  }
}
double dist(pair<double, double> a, pair<double, double> b) {
  return sqrt(pow((a.first - b.first), 2) + pow((a.second - b.second), 2));
}
double ism(double aa, long long p) {
  double ap = aa;
  double ans = 1;
  while (p > 0) {
    if (p & 1) {
      ans *= ap;
    }
    p /= 2;
    ap = ap * ap;
  }
  return ans;
}
long long ismm(long long aa, long long p, long long m) {
  long long ap = aa;
  long long ans = 1;
  while (p > 0) {
    if (p & 1) {
      ans = (ans * ap) % m;
    }
    p /= 2;
    ap = (ap * ap) % m;
  }
  return ans;
}
struct all_init {
  all_init() { cout << fixed << setprecision(12); }
} All_init;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> p;
  string o = "";
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  long long s = 0;
  bool flag = true;
  long long k = 1;
  long long a1 = -1, a2 = -1, a3 = -1;
  for (long long i = 0; i < m; i++) {
    if (a1 == -1 && p[i].first == 1) {
      a1 = p[i].second;
      if (n == 1) {
        cout << a1 << endl;
        exit(0);
      }
    } else if (a2 == -1 && p[i].first == 2) {
      a2 = p[i].second;
    } else if (a3 == -1 && p[i].first == 3) {
      a3 = p[i].second;
    }
  }
  if (n == 1 && a1 == 0) {
    cout << 0 << endl;
  }
  if (n != 1 && (a1 == 0 || a1 == -1)) {
    cout << -1 << endl;
    exit(0);
  }
  if (a2 == -1) {
    a2 = 0;
  }
  if (a3 == -1) {
    a3 = 0;
  }
  if (n == 1) {
    o = to_string(a1);
  } else if (n == 2) {
    o = to_string(a1) + to_string(a2);
  } else if (n == 3) {
    o = to_string(a1) + to_string(a2) + to_string(a3);
  }
  cout << o << endl;
}
