#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool res = false;
  int ans = -1;
  vector<pair<int, char>> a(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i].first >> a[i].second;
    a[i].first--;
  }
  int end = 1;
  for (int i = 0; i < n; ++i) end *= 10;
  for (int i = end / 10; i < end; ++i) {
    string tmp = to_string(i);
    bool flag = true;
    for (int j = 0; j < m; ++j) {
      if (tmp[a[j].first] != a[j].second) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  ;
}
