#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n, -1);
  int m, f = 0;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int p;
    int d;
    cin >> p >> d;
    if (v[p - 1] == -1)
      v[p - 1] = d;
    else {
      if (v[p - 1] != d) f = 1;
    }
  }
  int k;
  for (k = 0; k < n; k++) {
    if (v[k] == -1)
      v[k] = 1;
    else
      break;
  }
  for (int i = k; i < n; i++) {
    if (v[i] != -1)
      continue;
    else
      v[i] = 0;
  }
  if (f == 1 || (n > 1 && v[0] == 0))
    cout << -1;
  else if (n == 1 && m == 0)
    cout << 0;
  else {
    int sum = 0;
    for (int i = 1; i <= n; i++) sum = sum + v[i - 1] * pow(10, n - i);
    cout << sum;
  }
  return 0;
}
