#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N, M;
  cin >> N >> M;
  map<int, set<int>> mp;
  for (int i = 0; i < M; ++i) {
    int k, v;
    cin >> k >> v;
    mp[k].insert(v);
  }
  for (auto& p : mp)
    if (p.second.size() > 1) {
      cout << "-1\n";
      return 0;
    }
  vector<int> d(N + 1, -1);
  for (auto& p : mp) d[p.first] = *p.second.begin();
  if (d[1] == 0) {
    cout << "-1\n";
    return 0;
  }
  int ans = 0, factor = 1;
  for (int i = N; i >= 1; --i) {
    d[i] = (d[i] == -1 ? 0 : d[i]);
    ans += d[i] * factor;
    factor *= 10;
  }
  cout << ans << endl;
}
