#include <bits/stdc++.h>
using namespace std;
int main() {
  string ans = "-1";
  int n, m;
  cin >> n >> m;
  string s(n, '0');
  while (m--) {
    int a;
    char b;
    cin >> a >> b;
    if (s[a - 1] != '0') {
      break;
    } else {
      s[a - 1] = b;
    }
  }
  if (s[0] != '0' && s[s.size() - 1] != '0') {
    ans = s;
  }
  cout << ans << endl;
  return 0;
}
