#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  bool f = true;
  for (int i = 0; i < m; ++i) {
    if (a[s[i] - 1] != 0 && a[s[i] - 1] != c[i]) {
      f = false;
      break;
    }
    a[s[i] - 1] = c[i];
  }
  if (n > 1 && c[0] == 0) f = false;
  if (f) {
    for (auto x : a) cout << x;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
