#include <bits/stdc++.h>
using namespace std;
auto f = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
};
int main() {
  f();
  int n, m;
  cin >> n >> m;
  vector<int> arr(n, -1);
  while (m) {
    int a, b;
    cin >> a >> b;
    if (arr[a - 1] != -1 && arr[a - 1] != b) {
      cout << -1 << "\n";
      return 0;
    }
    arr[a - 1] = b;
    m--;
  }
  for (size_t i = 0; i < n; ++i) {
    if (arr[i] == -1) {
      arr[i] = 0;
    }
  }
  int ans = 0;
  int mult = pow(10, arr.size() - 1);
  bool z = true;
  for (size_t i = 0; i < arr.size(); ++i) {
    if (arr[i] != -1) {
      if (arr[i] == 0) {
        if (z && n > 1) {
          cout << -1 << "\n";
          return 0;
        }
        ans += (arr[i] * mult);
      } else {
        ans += (arr[i] * mult);
        z = false;
      }
    }
    mult /= 10;
  }
  cout << ans << "\n";
  return 0;
}
