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