#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}
ll lcm(ll n, ll m) { return abs(n * m) / gcd(n, m); }
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  bool ng = false;
  vector<int> v(m + 10);
  for (int i = (int)0; i < (int)m; ++i) {
    int s, c;
    cin >> s >> c;
    if (v[s - 1] != 0 && v[s - 1] != c) ng = true;
    if (s == 1 && c == 0) ng = true;
    if (s > n) ng = true;
    v[s - 1] = c;
  }
  string ans = "";
  for (int i = (int)0; i < (int)n; ++i) {
    if (i == 0) {
      if (v[0] == 0)
        ans += "1";
      else
        ans += to_string(v[0]);
    } else {
      if (v[i] != 0)
        ans += to_string(v[i]);
      else
        ans += "0";
    }
  }
  if (!ng)
    cout << ans;
  else
    cout << -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
