#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
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;
}
template <class T>
inline void printv(vector<T>& v) {
  int n = (int)v.size();
  for (int i = (0); i < ((n)); i++) cout << v[i] << (i == n - 1 ? '\n' : ' ');
}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  solve();
  return 0;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vi v(n, -1);
  int s, c;
  for (int i = (0); i < ((m)); i++) {
    cin >> s >> c;
    s--;
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << '\n';
      return;
    }
    if (v[s] == -1 || v[s] == c) v[s] = c;
  }
  bool b = false;
  string ans = "";
  for (int i = (0); i < ((n)); i++) {
    if (!b && i != n - 1 && v[i] == 0) break;
    if (!b && v[i] == -1) continue;
    if (b && v[i] == -1)
      ans += "0";
    else
      ans += to_string(v[i]);
    b = true;
  }
  if (ans == "")
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
