#include <bits/stdc++.h>
const double pi = M_PI;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = INT32_MAX;
  for (int i = (int)pow(10, n - 1); i < (int)pow(10, n); i++) {
    bool ok = true;
    string ss = to_string(i);
    for (int k = 0; k < m; k++) {
      if (ss[s[k] - 1] != c[k]) {
        ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  if (m == 0 && n == 1 || n == 1 && m == 1 && c[0] == 0) ans = 0;
  if (ans == INT32_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
