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