#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mm;
  cin >> n >> m;
  vector<vector<int>> sc(m, vector<int>(2));
  for (int i = 0; i < (int)(m); ++i) cin >> sc[i][0] >> sc[i][1];
  if (m == 1) {
    sc.push_back(sc[0]);
    mm = 2;
  } else {
    mm = m;
  }
  vector<int> a(n, 0);
  sort(sc.begin(), sc.end());
  for (int i = 0; i < (int)(m); ++i)
    cout << sc[i][0] << " " << sc[i][1] << endl;
  for (int i = 0; i < (int)(mm - 1); ++i) {
    if (n != 1 && sc[i][0] == 1 && sc[i][1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (sc[i][0] == sc[i + 1][0]) {
      if (sc[i][1] != sc[i + 1][1]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < (int)(m); ++i) a[sc[i][0] - 1] = sc[i][1];
  if (n != 1 && a[0] == 0) a[0] = 1;
  for (int i = 0; i < (int)(n); ++i) cout << a[i];
  cout << endl;
  return 0;
}
