#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  int a, b;
  bool f = 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
    if (a == 1 && b == 0) {
      f = 1;
    }
  }
  if (f == 1) {
    cout << -1 << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  int long long c = 0;
  for (int i = 0; i < m; i++) {
    if (i != 0 && v[i].first == v[i - 1].first &&
        v[i].second != v[i - 1].second) {
      cout << -1 << endl;
      return 0;
    } else if (i != 0 && v[i].first == v[i - 1].first &&
               v[i].second == v[i - 1].second) {
      continue;
    }
    c += pow(10, n - v[i].first) * v[i].second;
  }
  if (c < pow(10, n - 1)) {
    c += pow(10, n - 1);
  }
  cout << c << endl;
  return 0;
}
