#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
constexpr ll kMod = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  ll N, M;
  cin >> N >> M;
  vll S(M);
  vll C(M);
  umll SC;
  for (ll(i) = (0); (i) < (M); (i)++) {
    ll s, c;
    cin >> s >> c;
    S[i] = s;
    C[i] = c;
    if (SC.find(s) != SC.end() && SC.find(s)->second != c) {
      cout << "-1" << endl;
      return 0;
    }
    SC[s] = c;
  }
  stringstream ss;
  bool begin = false;
  for (ll(i) = (0); (i) < (N); (i)++) {
    if (SC.find(i + 1) != SC.end()) {
      ll a = SC.find(i + 1)->second;
      if ((!begin && a != 0) || begin) {
        ss << SC.find(i + 1)->second;
        if (SC.find(i + 1)->second != 0) {
          begin = true;
        }
      }
    } else if (!begin) {
    } else {
      ss << "0";
    }
  }
  if (!begin) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ss.str() << endl;
  return 0;
}
