#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  vector<pair<bool, int>> z(n, pair<bool, int>(false, 0));
  z[0].second = 1;
  for (int i = 0; i < m; i++) {
    cin >> sc[i].first >> sc[i].second;
    if (sc[i].first == 0 && sc[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (!z[sc[i].first - 1].first) {
      z[sc[i].first - 1].first = true;
      z[sc[i].first - 1].second = sc[i].second;
    } else if (z[sc[i].first - 1].second != sc[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (z[0].second == 0) {
    cout << -1 << endl;
  }
  for (int i = 0; i < n; i++) {
    cout << z[i].second;
  }
}
