#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
bool chmax(T &a, const S &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class S>
bool chmin(T &a, const S &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long n, long long m) { return (m ? gcd(m, n % m) : n); }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  vector<long long> ans(n);
  for (long long i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (ans[s[i]] && ans[s[i]] != c[i]) {
      cout << -1 << '\n';
      return 0;
    }
    if (n != 1 && s[i] == 0 && c[i] == 0) {
      cout << -1 << '\n';
      return 0;
    }
    ans[s[i]] = c[i];
  }
  if (n != 1) ans[0] = 1;
  for (long long i : ans) cout << i;
  cout << '\n';
}
