#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  int smax = 0;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    chmax(smax, s[i]);
    s[i]--;
    if (s[i] == 0 && c[i] == 0) {
      cout << -1 << "\n";
      return 0;
    }
  }
  string ret(smax, 'a');
  for (int i = 0; i < n; ++i) {
    if (ret[s[i]] == 'a') {
      ret[s[i]] = '0' + c[i];
    } else if (ret[s[i]] - '0' != c[i]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (ret[0] == 'a') ret[0] = '1';
  for (int i = 0; i < smax; ++i) {
    if (ret[i] == 'a') ret[i] = '0';
  }
  cout << ret << "\n";
  return 0;
}
