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