#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
namespace {
template <typename T>
void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <typename T>
void chmin(T& a, T b) {
  a = std::min(a, b);
}
template <typename T>
void chadd(T& a, T b) {
  a = a + b;
}
template <typename T>
void Cout(T& x, char end = '\n') {
  std::cout << x << end;
}
template <typename T>
void Cout(std::vector<T>& x, char sep = ' ', char end = '\n') {
  for (std::size_t i = 0, sz = x.size(); i < sz; i++) {
    std::cout << x[i] << (i == sz - 1 ? end : sep);
  }
}
struct inp {
  size_t sz;
  inp(size_t _sz = 1) : sz(_sz) {}
  template <typename T>
  operator T() const {
    T a;
    std::cin >> a;
    return a;
  }
  template <typename T>
  operator std::vector<T>() const {
    vector<T> a(sz);
    for (std::size_t i = 0; i < sz; i++) std::cin >> a[i];
    return a;
  }
  template <typename T, typename U>
  operator std::pair<T, U>() const {
    T f;
    U s;
    std::cin >> f >> s;
    return std::pair<T, U>(f, s);
  }
};
inp inp1;
}  // namespace
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  int max_num = 0;
  map<int, int> mp;
  bool out = false;
  for (int i = 0; i < m; ++i) {
    chmax(max_num, s[i]);
    if (mp.find(s[i]) != mp.end()) {
      if (mp[s[i]] != c[i]) {
        out = true;
        break;
      }
    }
    mp[s[i]] = c[i];
  }
  if (out) {
    cout << -1 << endl;
  } else {
    if (m == 0)
      cout << -1 << endl;
    else {
      for (int i = 1; i <= max_num; ++i) {
        cout << mp[i];
      }
      cout << endl;
    }
  }
  return 0;
}
