#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (int i = 0; i < (m); ++i) cin >> a[i].first >> a[i].second;
  vector<int> res(n, 0);
  bool exist = true;
  for (int i = 0; i < (m); ++i) {
    if (a[i].first == 1 && a[i].second == 0) exist = false;
    if (res[a[i].first - 1] != 0 && res[a[i].first - 1] != a[i].second)
      exist = false;
    res[a[i].first - 1] = a[i].second;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans += res[i] * pow(10, n - i - 1);
  }
  if (exist)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
