#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<set<int> > a(n);
  int d, e;
  for (int i = 0; i < m; ++i) {
    cin >> d >> e;
    a[d - 1].insert(e);
  }
  if (n == 1 && m == 0) {
    cout << 0 << "\n";
  }
  vector<int> b;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      if (a[i].empty()) {
        b.push_back(1);
      } else if (a[i].size() > 1) {
        cout << -1 << "\n";
        return 0;
      } else {
        if (*a[i].begin() == 0) {
          cout << -1 << "\n";
          return 0;
        } else {
          b.push_back(*a[i].begin());
        }
      }
    } else {
      if (a[i].size() > 1) {
        cout << -1 << "\n";
        return 0;
      } else if (a[i].empty()) {
        b.push_back(0);
      } else {
        b.push_back(*a[i].begin());
      }
    }
  }
  for (int i : b) {
    cout << i;
  }
  cout << "\n";
  return 0;
}
