#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> s;
  int x, y;
  for (int i = 0; i < (M); ++i) {
    cin >> x >> y;
    if (s.count(x)) {
      if (s.at(x) != y) break;
    } else
      s[x] = y;
  }
  if (N != 1 && s[1] == 0) {
    cout << -1;
  } else {
    for (int i = 1; i <= N; i++) {
      if (s.count(i))
        cout << s.at(i);
      else
        cout << 0;
    }
  }
  cout << endl;
  return 0;
}
