#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, -1);
  int m;
  cin >> m;
  for (int it = 0; it < int(m); it++) {
    int pos, d;
    cin >> pos >> d;
    pos--;
    if (a[pos] == -1)
      a[pos] = d;
    else if (a[pos] != d) {
      cout << "-1\n";
      return 0;
    }
  }
  if (a[0] == 0 && n != 1) {
    cout << "-1\n";
    return 0;
  }
  if (a[0] == -1) a[0] = 1;
  for (int x : a) {
    cout << max(0, x);
  }
  cout << "\n";
  return 0;
}
