#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  long long ans = 0;
  for (int i = 0; i < (int)(1000); i++) {
    string num = to_string(i);
    if (num.length() != n) {
      continue;
    }
    bool ok = true;
    for (int j = 0; j < (int)(m); j++) {
      if (num[s[j] - 1] != c[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  if (ans != 0) {
    cout << ans;
  } else {
    cout << -1;
  }
}
