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