#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> digits(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (digits[s] != -1 && digits[s] != c) {
      cout << -1 << endl;
      return 0;
    } else {
      digits[s] = c;
    }
  }
  if (n == 1 && digits[0] == -1) {
    cout << 0 << endl;
    return 0;
  }
  if (n > 1 && digits[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (i == 0 && digits[i] == -1) {
      digits[i] = -1;
    } else if (digits[i] == -1) {
      digits[i] = 0;
    }
  }
  int num = 0;
  int base = 1;
  for (int i = n - 1; i >= 0; --i) {
    num += base * digits[i];
    base *= 10;
  }
  cout << num << endl;
  return 0;
}
