#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int inf = 2e5;
  vector<int> s(n + 1, inf);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (s[x] != inf && s[x] != y) {
      cout << -1 << endl;
      return 0;
    }
    s[x] = y;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (s[i + 1] == 0) {
        cout << -1 << endl;
        return 0;
      } else if (s[i + 1] == inf) {
        cout << 1;
        continue;
      }
    }
    if (s[i + 1] == inf) {
      cout << 0;
      continue;
    }
    cout << s[i + 1];
  }
  return 0;
}
