#include <bits/stdc++.h>
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];
  }
  string ans = "";
  for (int i = 0; i < n; i++) {
    ans += "0";
  }
  for (int i = 0; i < m; i++) {
    ans.at(s[i] - 1) = c[i];
  }
  for (int i = 0; i < m; i++) {
    if (ans.at(s[i] - 1) != c[i]) {
      ans = "-1";
      cout << ans << endl;
      return 0;
    }
  }
  if (ans.at(0) == '0') {
    if (n != 1) {
      ans.at(0) = '1';
    } else {
      ans = "-1";
    }
  }
  cout << ans << endl;
  return 0;
}
