#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--;
  }
  int ans = 0;
  int mult = pow(10, arr.size() - 1);
  for (size_t i = 0; i < arr.size(); ++i) {
    if (arr[i] != -1) ans += (arr[i] * mult);
    mult /= 10;
  }
  if (ans == 0)
    cout << (n == 1 ? ans : -1) << "\n";
  else
    cout << ans << "\n";
  return 0;
}
