#include <bits/stdc++.h>
using namespace std;
template <typename T>
constexpr auto inf = numeric_limits<T>::max() / 4;
constexpr int INF = inf<int>;
constexpr long long LINF = inf<long long>;
template <typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}
template <typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}
template <typename T>
void dumpContents(const T& v, const string& msg) {
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
  }
} before_main_function;
vector<pair<int, int> > R;
bool check(int x) {
  vector<int> v;
  while (x > 0) {
    v.emplace_back(x % 10);
    x /= 10;
  }
  reverse(begin(v), end(v));
  for (auto p : R) {
    if (v[p.first - 1] != p.second) return false;
  }
  return true;
}
int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  for (int i = 0, i_l = (M); i < i_l; ++i) {
    int s, c;
    cin >> s >> c;
    R.emplace_back(s, c);
  }
  int imax = 1;
  for (int i = 0, i_l = (N); i < i_l; ++i) {
    imax *= 10;
  }
  int imin = imax / 10;
  if (imin == 1) imin = 0;
  for (int i = imin, i_l = (imax); i < i_l; ++i) {
    if (check(i)) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
