#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K>
using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
template <class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) out << list[i] << ' ';
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) in >> list[i];
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
  ll n = list.size();
  for (ll i = 0; i < (ll)(n); i++) out << list[i] << '\n';
  return out;
}
void solve() {
  ll n, m;
  cin >> n >> m;
  vl s(m), c(m);
  for (ll i = 0; i < (ll)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (ll i = 0; i < 1000; ++i) {
    string num_str = to_string(i);
    bool ok = true;
    if (num_str.size() != n) {
      ok = false;
      continue;
    }
    for (ll j = 0; j < (ll)(m); j++) {
      if (num_str[s[j] - 1] != c[j]) {
        ok = false;
        continue;
      }
    }
    if (ok) {
      cout << num_str << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
int main() {
  solve();
  return 0;
}
