#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K>
using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
template <class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) out << list[i] << ' ';
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) in >> list[i];
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) out << list[i] << '\n';
  return out;
}
void solve() {
  ll n, m;
  cin >> n >> m;
  vl ans(n, -1);
  for (ll i = 0; i < (ll)(m); i++) {
    ll s, c;
    cin >> s >> c;
    s--;
    if (ans[s] == -1)
      ans[s] = c;
    else if (ans[s] != c) {
      cout << -1 << '\n';
      return;
    }
  }
  if (ans[0] == -1 && n == 1)
    ans[0] = 0;
  else {
    if (ans[0] == -1) ans[0] = 1;
    for (ll i = 1; i < n; ++i) {
      if (ans[i] == -1) ans[i] = 0;
    }
  }
  string str = 0;
  for (ll i = 0; i < (ll)(n); i++) {
    str += (ans[i] - '0');
  }
  cout << str << '\n';
}
int main() {
  solve();
  return 0;
}
