#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> cs(m);
  for (int i = 0; i < m; i++) {
    cin >> cs[i].first >> cs[i].second;
  }
  int s = 1;
  for (int i = 0; i < n - 1; i++) {
    s *= 10;
  }
  int e = s * 10;
  int ans = -1;
  for (int k = s; k < e; k++) {
    bool is_ok = true;
    for (auto c : cs) {
      int nc = n - c.first;
      int d = k;
      for (int i = 0; i < nc; i++) {
        d /= 10;
      }
      d %= 10;
      if (d != c.second) {
        is_ok = false;
        break;
      }
    }
    if (is_ok) {
      ans = k;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
