#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int countDigit(long long int n) { return floor(log10(n) + 1); }
static const long long int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m) {
  for (auto p : m) os << "<" << p.first << ", " << p.second << "> ";
  return os;
}
int main() {
  long long int N, M;
  cin >> N >> M;
  vector<pair<long long int, long long int> > vec(M);
  for (long long int i = 0LL; i < (long long int)(M); i++) {
    long long int s, c;
    cin >> s >> c;
    vec[i] = pair<long long int, long long int>(s, c);
  }
  for (long long int i = (long long int)pow(10, N - 1);
       i < (long long int)(pow(10, N)); i++) {
    string tmp = to_string(i);
    bool flag = false;
    for (pair<long long int, long long int> p : vec) {
      if (tmp[p.first - 1] - '0' != p.second) {
        flag = true;
      }
    }
    if (!flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
