#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, r;
  char c;
  cin >> n >> m;
  string s;
  for (int i = 0; i < int(n); i++) s += 'a';
  for (int i = 0; i < int(m); i++) {
    cin >> r >> c;
    r--;
    if (s[r] == 'a' || s[r] == c)
      s[r] = c;
    else {
      cout << -1 << '\n';
      exit(0);
    }
  }
  for (int i = 0; i < int(n); i++) {
    if ((s[i] == 'a' || s[i] == '0') && i == 0) {
      cout << -1 << '\n';
      exit(0);
    }
    if (s[i] == 'a') s[i] = '0';
  }
  int fin = stoi(s);
  cout << fin << '\n';
  return 0;
}
