#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m + 1];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  c[m] = '\0';
  char ans[n + 1];
  ans[n] = '\0';
  for (int i = 0; i < n; i++) ans[i] = 'a';
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] == 'a' || ans[s[i] - 1] == c[i])
      ans[s[i] - 1] = c[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n != 1 && ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0 && ans[i] == 'a')
      cout << 1;
    else if (ans[i] == 'a')
      cout << 0;
    else
      cout << ans[i];
  }
  cout << endl;
}
