#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
  int n, m;
  int s, c;
  vector<int> sv, cv;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    sv.push_back(s);
    cv.push_back(c);
  }
  int ans = 0;
  int table[n];
  for (int i = 0; i < (int)(n); i++) {
    table[i] = -1;
  }
  for (int i = 0; i < (int)(m); i++) {
    if (sv[i] == 1 && cv[i] == 0 && n != 1) {
      ans = -1;
      cout << ans << endl;
      return 0;
    } else if (table[sv[i] - 1] != cv[i] && table[sv[i] - 1] != -1) {
      ans = -1;
      cout << ans << endl;
      return 0;
    } else
      table[sv[i] - 1] = cv[i];
  }
  int muln = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (table[i] != -1) ans += table[i] * muln;
    muln *= 10;
  }
  cout << ans << endl;
  return 0;
}
