#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> cond(m);
  for (int i = 0; i < m; i++) {
    cin >> cond[i].first >> cond[i].second;
    cond[i].first--;
  }
  for (int i = 0; i < pow(10, n + 1); i++) {
    int temp = i;
    vector<int> num;
    if (temp == 0) num.push_back(0);
    while (temp > 0) {
      num.push_back(temp % 10);
      temp /= 10;
    }
    if (num.size() < n) break;
    reverse(num.begin(), num.end());
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (num[cond[j].first] != cond[j].second) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
