#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M];
  string c[M];
  for (long long(i) = 0; (i) < (M); (i)++) cin >> s[i] >> c[i];
  string res = "";
  for (long long(i) = 0; (i) < (N); (i)++) res += "0";
  for (long long(i) = 0; (i) < (M); (i)++) {
    res.erase((s[i] - 1), 1);
    res.insert((s[i] - 1), c[i]);
  }
  if (res[0] == '0')
    cout << -1;
  else
    cout << res;
  return 0;
}
