#include <bits/stdc++.h>
using namespace std;
const long long INF = 1001001001001001001ll;
const long long LINF = 1001001001001001001ll;
const long long MOD = 1000000007;
const double EPS = 1e-9;
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  long long len = v.size();
  for (long long i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << ' ';
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  long long len = vv.size();
  for (long long i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1) s << '\n';
  }
  return s;
}
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;
}
__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  bool flag = false;
  for (long long i = 0; i < (M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (s[i] == 0 && c[i] == 0) flag = true;
  }
  vector<long long> ans(N, -1);
  for (long long i = 0; i < (M); ++i) {
    if (ans[s[i]] == -1)
      ans[s[i]] = c[i];
    else {
      if (ans[s[i]] != c[i]) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  for (long long i = 0; i < (N); ++i) {
    if (ans[i] == -1) ans[i] = 0;
  }
  if (ans[0] == 0 && N != 0) {
    if (flag) {
      cout << -1 << '\n';
      return 0;
    } else
      ans[0] = 1;
  }
  for (long long i = 0; i < (N); ++i) {
    cout << ans[i];
  }
  cout << '\n';
}
