#include <bits/stdc++.h>
using namespace std;
int countDigits(int n) {
  int cnt = 0;
  while (n != 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}
int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> digits(n, -1);
  bool exists = true;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    int idx = n - s;
    if (digits[idx] != -1 && digits[idx] != c) {
      exists = false;
      break;
    }
    digits[idx] = c;
  }
  if (!exists || digits[n - 1] <= 0) {
    cout << -1 << "\n";
  } else {
    int result = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (digits[i] == -1) {
        continue;
      }
      result += pow(10, i) * digits[i];
    }
    cout << result << "\n";
  }
  return 0;
}
