#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1e9 + 7;
const ll INF = 1ll << 60;
int N, M;
int main() {
  cin >> N >> M;
  map<int, int> mp;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    auto itr = mp.find(s);
    if (itr != mp.end()) {
      if (c != itr->second) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      mp[s] = c;
    }
  }
  auto itr = mp.find(1);
  if (itr != mp.end()) {
    if (itr->second == 0 && N != 1) {
      cout << -1 << endl;
      return 0;
    }
    cout << mp[1];
  } else {
    mp[1] = 1;
    cout << mp[1];
  }
  for (int i = 2; i <= N; i++) {
    itr = mp.find(i);
    if (itr == mp.end()) {
      mp[i] = 0;
    }
    cout << mp[i];
  }
  cout << endl;
  return 0;
}
