#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] = "a";
  }
  for (int i = 0; i < (m); i++) {
    if (ans[s[i] - 1] != "a" && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == "a" || ans[0] == "0" && ans.size() != 1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < (n); i++) {
      cout << (ans[i] != "a" ? ans[i] : "0");
    }
    cout << endl;
  }
  return 0;
}
