#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (int i = (int)(0); i < (int)(M); i++) {
    cin >> s[i];
    cin >> c[i];
  }
  long long num[N];
  for (int i = (int)(0); i < (int)(N); i++) {
    num[i] = -1;
  }
  for (int i = (int)(0); i < (int)(M); i++) {
    if (num[s[i] - 1] == -1 or num[s[i] - 1] == c[i]) {
      num[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  bool number_exist = false;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (num[i] == -1) {
      if (number_exist == true) {
        cout << 0;
      } else {
        cout << 1;
        number_exist = true;
      }
    } else {
      cout << num[i];
      number_exist = true;
    }
  }
  cout << endl;
  return 0;
}
