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