#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vc(m + 1, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (vc[s - 1] == -1 || vc[s - 1] == c) {
      vc[s - 1] = c;
    } else {
      vc.back() = 10;
    }
  }
  for (int i = 0; i < n; i++) {
    if (vc[i] == -1) {
      vc[i] = 0;
    }
  }
  string ans;
  if (n == 1) {
    ans = to_string(vc.front());
  } else {
    if (vc.front() == 0 || vc.back() == 10) {
      ans = "-1";
    } else {
      for (int i = 0; i < n; i++) {
        ans += to_string(vc[i]);
      }
    }
  }
  cout << ans << endl;
}
