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