#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = (int)0; i < (int)m; ++i) {
    cin >> s[i] >> c[i];
  }
  string ans;
  for (int i = (int)0; i < (int)n; ++i) {
    ans += "0";
  }
  for (int i = (int)0; i < (int)m; ++i) {
    ans[s[i] - 1] = c[i];
  }
  if ((ans.size() != 1 && ans[0] == '0')) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
