#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int const inf = 1e9;
long long const INF = 1e18;
inline void ios_() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <typename T>
int size(const T& a) {
  return (int)a.size();
}
template <typename T>
T Div(T a, T b) {
  return (a + b - 1) / b;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for (int(i) = 0; (i) < (m); (i)++) cin >> v[i].first >> v[i].second;
  int ans = -1;
  int ma = (int)pow(10, n);
  int mi = ma / 10;
  for (int(i) = (mi); (i) < (ma); i++) {
    int ok = true;
    for (int(j) = 0; (j) < (m); (j)++) {
      int s = v[j].first, c = v[j].second;
      int x = i;
      for (int(k) = 0; (k) < (n - s); (k)++) x /= 10;
      ok &= (x % 10 == c);
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
