#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> c(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> digit(n, -1);
  for (int j = 0; j < n; j++) {
    int oldDigit = -1;
    for (int i = 0; i < m; i++) {
      if (s[i] == (j + 1)) {
        if (oldDigit == -1) {
          oldDigit = c[i];
          digit[n - 1 - j] = c[i];
        } else {
          if (oldDigit == c[i]) {
          } else {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }
  int value = 0;
  if (digit[n - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (digit[n - 1] == -1) digit[n - 1] = 1;
  for (int i = 0; i < n; i++) {
    if (digit[i] != -1) {
      value += digit[i] * pow(10, i);
    }
  }
  if (value < pow(10, n - 1)) {
    cout << -1 << endl;
    return 0;
  }
  cout << value << endl;
  return 0;
}
