#include <bits/stdc++.h>
using namespace std;
std::istringstream ss;
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  bool jud = true;
  for (long long i = 0; i < (m); ++i) {
    cin >> a[i].first >> a[i].second;
  }
  vector<int> d(n, -1);
  bool jud2 = false;
  for (long long i = 0; i < (m); ++i) {
    if (d[a[i].first - 1] != -1 && d[a[i].first - 1] != a[i].second) {
      jud = false;
      break;
    }
    d[a[i].first - 1] = a[i].second;
  }
  if (d[0] == 0 && n == 1) jud = false;
  for (long long i = 0; i < (n); ++i) {
    if (d[i] == -1) d[i] = 0;
  }
  if (d[0] == 0 && n != 1) d[0] = 1;
  if (jud) {
    for (long long i = 0; i < (n); ++i) {
      cout << d[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
