#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<long long>;
using pll = pair<long long, long long>;
template <class T>
using pr = pair<T, T>;
template <class T>
using vec = vector<T>;
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007;
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T divup(T a, T b) {
  if (a % b == 0) {
    return a / b;
  }
  return a / b + 1;
}
std::string strMulti(std::string t, int n) {
  std::string out = "";
  for (int i = 0; i < n; i++) {
    out += t;
  }
  return out;
}
template <class T>
T math_P(T m, T n) {
  T ret = 1;
  for (T i = m; i > m - n; i--) {
    ret *= i;
  }
  return ret;
}
template <class T>
T math_C(T m, T n) {
  T ret = math_P(m, n);
  for (T i = 2; i <= n; i++) {
    ret /= i;
  }
  return ret;
}
template <class T>
bool compare_by_b(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  }
  return a.first < b.first;
}
template <class T>
T mod_pow(T x, T n, const T& p) {
  T ret = 1;
  while (n > 0) {
    if (n & 1) {
      (ret *= x) %= p;
    }
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
void Main() {
  ll N, M;
  cin >> N >> M;
  vec<pll> c(M);
  for (ll i = 0, i_len = (M); i < i_len; ++i) cin >> c[i].first >> c[i].second;
  sort((c).begin(), (c).end());
  ll ret = 0;
  int backS = -1;
  for (ll i = 0, i_len = (M); i < i_len; ++i) {
    if (i == 0 && c[i].first != 1) {
      ret += (ll)pow(10, N - 1);
    }
    if (c[i].first == 1 && c[i].second == 0 && N != 1) {
      ret = -1;
      break;
    }
    if (backS == c[i].first) {
      if (c[i - 1].second != c[i].second) {
        ret = -1;
        break;
      } else {
        continue;
      }
    }
    ret += (ll)pow(10, N - c[i].first) * c[i].second;
    (std::cerr << "(ll)pow(10, N - c[i].first) * c[i].second"
               << " : " << ((ll)pow(10, N - c[i].first) * c[i].second) << "\n");
    backS = c[i].first;
  }
  cout << ret;
}
int main() {
  Main();
  cout << endl;
  return 0;
}
