#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
template <class T>
bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
T sqar(T x) {
  return x * x;
}
template <class T>
inline void princ(T x) {
  cout << x << " ";
};
template <class T>
inline void print(T x) {
  cout << x << "\n";
};
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
ll n, m;
Vi s, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for (ll i = 0; i < (ll)m; i++) {
    cin >> s[i] >> c[i];
  }
  Vi v(n, -1);
  bool flg = true;
  for (ll i = 0; i < (ll)m; i++) {
    if (v[s[i] - 1] == -1 || v[s[i] - 1] == c[i]) {
      v[s[i] - 1] = c[i];
    } else {
      flg = false;
      break;
    }
  }
  if (flg) {
    for (ll i = 0; i < (ll)n; i++) {
      if (i == 0) {
        if (v[i] == -1) v[i] = 1;
      } else {
        if (v[i] == -1) v[i] = 0;
      }
    }
  }
  if (flg) {
    string s;
    for (ll i = 0; i < (ll)n; i++) {
      s += to_string(v[i]);
    }
    if (v[0] == 0 && v.size() > 1)
      print(-1);
    else
      print(s);
  } else {
    print(-1);
  }
  return 0;
}
