#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    vec.push_back(make_pair(s, c));
  }
  bool flag;
  for (int i = 0; i < 1000; ++i) {
    if ((i == 0 && n != 0) || (i < pow(10, n - 1) || pow(10, n) <= i)) continue;
    flag = true;
    for (auto &v : vec) {
      int s = v.first;
      int c = v.second;
      if (c != ((i / int(pow(10, n - s))) % 10)) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return EXIT_SUCCESS;
    }
  }
  cout << -1 << endl;
}
