#include <bits/stdc++.h>
using namespace std;
template <typename Arg1, typename Arg2>
ostream& operator<<(ostream& out, const pair<Arg1, Arg2>& x) {
  return out << "(" << x.first << "," << x.second << ")";
}
template <typename Arg1>
ostream& operator<<(ostream& out, const vector<Arg1>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1>
ostream& operator<<(ostream& out, const set<Arg1>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1, typename Arg2>
ostream& operator<<(ostream& out, const map<Arg1, Arg2>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args) {
  const string name = names.substr(0, names.find(','));
  cerr << name << " : " << arg1 << " | ";
  __trace__(names.substr(1 + (int)name.size()), args...);
}
clock_t time_p = clock();
void time_taken() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const long long mod = 1e9 + 7;
const long long INF = 1e18;
int n, m;
int ans = -1;
vector<pair<int, int>> a;
void f(int i, int num) {
  if (i == n) {
    vector<int> foo;
    int memo = num;
    int cnt = 0;
    while (num) {
      foo.push_back(num % 10);
      num /= 10;
      cnt++;
    }
    if (cnt == 0) cnt++;
    if (cnt != n) return;
    reverse(foo.begin(), foo.end());
    bool ok = 1;
    for (pair<int, int> p : a) {
      ok &= (foo[p.first] == p.second);
    }
    if (ok) {
      cout << memo << '\n';
      exit(0);
    }
    return;
  }
  for (int d = 0; d < 9; d++) {
    f(i + 1, num * 10 + d);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(12);
  cout << fixed;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int ind, x;
    cin >> ind >> x;
    ind--;
    a.push_back({ind, x});
  }
  f(0, 0);
  cout << -1 << '\n';
  time_taken();
  return 0;
}
