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