#include <bits/stdc++.h>
template <size_t i>
std::bitset<i> operator++(std::bitset<i> b, int) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  return b = (unsigned long long)b + 1;
}
template <size_t i>
std::bitset<i> operator++(std::bitset<i> b) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  auto temp = b;
  b++;
  return temp;
}
template <size_t i>
std::bitset<i> operator--(std::bitset<i> b, int) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  return b = (unsigned long long)b - 1;
}
template <size_t i>
std::bitset<i> operator--(std::bitset<i> b) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  auto temp = b;
  b--;
  return temp;
}
long long constexpr inf = std::numeric_limits<long long>::max();
using namespace std;
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n, 0);
  vector<long long> v2(n, -1);
  for (long long i = 0; i < (n); ++i) {
    int t, k;
    cin >> t >> k;
    --t;
    if (v2[t] != -1 && v2[t] != k) {
      cout << -1;
      return 0;
    }
    v2[t] = k;
  }
  if (n != 1 && v[0] == -1) {
    cout << -1;
    return 0;
  }
  if (v2[0] == 0) {
    cout << -1;
    return 0;
  }
  for (auto &&x = v2.begin(); x != v2.end(); ++x) {
    if (x == v2.begin() && *x == -1) {
      cout << 1;
    }
    cout << (*x == -1 ? 0 : *x);
  }
  return 0;
}
