#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template <class T>
constexpr int sz(const T& a) {
  return (int)a.size();
}
template <class T>
constexpr T pow2(const T a) {
  return a * a;
}
template <class T, class... Args>
constexpr T mins(T& a, Args... args) {
  return a = min<T>({a, args...});
}
template <class T, class... Args>
constexpr T maxs(T& a, Args... args) {
  return a = max<T>({a, args...});
}
template <typename A, size_t N, typename T>
void fillArray(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
int n, m;
int s[10], c[10];
int num[10];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) cin >> s[i] >> c[i];
  bool ok = true;
  for (int i = 0; i < (int)(n); ++i) num[i] = -1;
  for (int i = 0; i < (int)(m); ++i) {
    if (num[s[i] - 1] != -1 && num[s[i] - 1] != c[i]) ok = false;
    num[s[i] - 1] = c[i];
  }
  if (num[0] == -1) num[0] = 1;
  if (!ok || n != 1 && num[0] == 0) {
    cout << -1 << endn;
    return;
  }
  for (int i = 0; i < (int)(n); ++i)
    if (num[i] == -1)
      cout << 0;
    else
      cout << num[i];
  cout << endn;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  cout << flush;
  return 0;
}
