#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    sc.emplace_back(s, c);
  }
  sort(sc.begin(), sc.end());
  bool left_zero = false;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    int s = sc[i].first;
    if (s > m) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 1 && sc[i].second == 0) left_zero = true;
    if (ans[s - 1] == -1)
      ans[s - 1] = sc[i].second;
    else {
      if (ans[s - 1] != sc[i].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n != 1 && left_zero) {
    cout << -1 << endl;
    return 0;
  }
  if (n != 1 && ans[0] == 0) ans[0] = 1;
  for (int i = 0; i < n; ++i)
    if (ans[i] == -1) ans[i] = 0;
  int tmp = ans[0];
  for (int i = 1; i < n; ++i) tmp *= 10, tmp += ans[i];
  cout << tmp << endl;
}
