#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
signed main() {
  int n, m;
  cin >> n >> m;
  int start, end;
  if (n == 1) {
    start = 1;
    end = 9;
  }
  if (n == 2) {
    start = 10;
    end = 99;
  }
  if (n == 3) {
    start = 100;
    end = 999;
  }
  vector<pair<int, int> > vec;
  int temp = m;
  while (m--) {
    int s, c;
    cin >> s >> c;
    vec.push_back({--s, c});
  }
  if (n == 1 && temp == 1) {
    if (vec[0].first == 0 && vec[0].second == 0) {
      cout << 0;
      return 0;
    }
  }
  int flag = 0;
  for (int i = start; i <= end; i++) {
    string s = to_string(i);
    int f = 0;
    for (auto it : vec) {
      if (s[it.first] == it.second + '0')
        continue;
      else {
        f++;
        break;
      }
    }
    if (!f) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
