#include <bits/stdc++.h>
using namespace std;
bool check(vector<pair<int, int>> &p, int n) {
  vector<int> v;
  do {
    v.push_back(n % 10);
    n /= 10;
  } while (n != 0);
  reverse(v.begin(), v.end());
  for (auto x : p) {
    if (x.first + 1 > v.size() || v[x.first] != x.second) {
      return false;
    }
  }
  return true;
}
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<int, int>> p;
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    p.push_back({s, c});
  }
  sort(p.begin(), p.end());
  if (p[0].second == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = (long long)(pow(10, n - 1)); i < (long long)(pow(10, n));
       ++i) {
    if (check(p, i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
