#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int guess = 0;
  map<int, int> overlap;
  map<int, int> mp;
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (mp[s] != c) {
      overlap[s]++;
      guess += c * pow(10, n - s);
    }
    mp[s] = c;
    if (s > n) {
      guess = -1;
      break;
    }
    if (s == 1 && c == 0) {
      guess = -1;
      break;
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (overlap[i + 1] > 1) guess = -1;
  }
  cout << guess << endl;
}
