#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1000000000000000000LL;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<string> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  vector<string> ans(n);
  for (int i = 0; i < (n); i++) {
    ans[i] = "0";
  }
  for (int i = 0; i < (m); i++) {
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == "0")
    cout << -1 << endl;
  else {
    for (int i = 0; i < (n); i++) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
