#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9) + 7;
using namespace std;
using pii = pair<int, int>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  bool ok[5] = {false};
  int n, m;
  cin >> n >> m;
  char st[5];
  int s;
  char c;
  for (int i = 0; i < (m); i++) {
    cin >> s >> c;
    st[s] = c;
    if (ok[s] && st[s] != c) {
      cout << -1 << '\n';
      return 0;
    }
    ok[s] = true;
  }
  if (ok[1] == false && n == 2) {
    cout << -1 << '\n';
    return 0;
  }
  if ((ok[1] == false || (ok[2] == false && ok[1] == false)) && n == 3) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= (n); i++) {
    if (ok[i]) {
      cout << st[i];
    } else {
      cout << 0;
    }
  }
  cout << '\n';
  return 0;
}
