#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans = -1;
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    if (n == 1 && i == 1) i--;
    string num = to_string(i);
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (num[s[j]] != c[j]) f = false;
    }
    if (f) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
