#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
  }
  string num = "";
  for (int i = 0; i < (int)(N); i++) {
    num.push_back('0');
  }
  for (int i = 0; i < (int)(M); i++) {
    num[s[i] - 1] = c[i];
  }
  if (num[0] != '0')
    cout << num << endl;
  else
    cout << "-1" << endl;
  return 0;
}
