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