#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  string ans = "-1";
  int k = 10;
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  if (n > 1 && c[0] == '0') {
    ans = "-1";
    goto end;
  }
  for (int i = 1; i <= n; ++i) k *= 10;
  for (int i = 0; i < k; ++i) {
    string tmp = to_string(i);
    bool f = true;
    for (int j = 0; j < m; ++j) {
      if (tmp[s[j] - 1] != c[j]) {
        f = false;
        break;
      }
    }
    if (f) {
      ans = tmp;
      break;
    }
  }
end:;
  cout << ans << endl;
  return 0;
}
