#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (n > 1 && s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans.at(s) == -1) {
      ans.at(s) = c;
    } else {
      if (ans.at(s) != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (ans.at(i) == -1) {
      cout << 0;
    } else {
      cout << ans.at(i);
    }
  }
  cout << endl;
  return 0;
}
