#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  for (int i = 0; i < (m); i++) {
    if (s[i] == 1 && c[i] == 0 && n != 1) {
      cout << "-1" << endl;
      return 0;
    }
    for (int j = 0; j < (m); j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  vector<int> min(n, -1);
  for (int i = 0; i < (m); i++) min[s[i] - 1] = c[i];
  for (int i = 0; i < (n); i++) {
    if (min[i] == -1) {
      min[i] = 0;
    }
  }
  if (min[0] == 0) min[0]++;
  for (int i = 0; i < (n); i++) {
    cout << min[i];
  }
  cout << endl;
  return 0;
}
