#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  string ans = "aaa";
  for (int i = 0; i < (m); i++) {
    if (ans[s[i]] == 'a') {
      ans[s[i]] = c[i];
    } else if (ans[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == '0') {
    if (!(ans[1] == '0' || ans[1] == 'a')) {
      cout << -1 << endl;
      return 0;
    } else if (!(ans[2] == '0' || ans[2] == 'a')) {
      cout << -1 << endl;
      return 0;
    } else {
      if (n == 1) {
        cout << 0 << endl;
        return 0;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  string t;
  if (ans[0] == 'a') {
    t.push_back('1');
  } else {
    t.push_back(ans[0]);
  }
  for (int i = 1; i <= 2; i++) {
    if (ans[i] == 'a') {
      t.push_back('0');
    } else {
      t.push_back(ans[i]);
    }
  }
  if (t.size() == n) {
    cout << t << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
