#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0, A[3];
  bool flag = true;
  for (int i = 0; i < 3; i++) {
    A[i] = -1;
  }
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (A[n - s] != -1) {
      if (A[n - s] == c) continue;
      flag = false;
      continue;
    }
    A[n - s] = c;
    ans += c * pow(10, n - s);
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (A[n - 1] == -1 || (A[n - 1] == 0 && n != 1))
    cout << -1 << endl;
  else if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
