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