#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0;
  bool flag = true;
  cin >> n >> m;
  vector<pair<long long, long long>> s(m);
  for (long long i = 0; i < m; i++) cin >> s[i].first >> s[i].second;
  sort(s.begin(), s.end());
  for (long long i = 0; i < s.size() - 1; i++)
    if (s[i].first == s[i + 1].first && s[i].second == s[i + 1].second)
      s.erase(s.begin() + i + 1);
  s.push_back({0, 0});
  for (long long i = 0; i < s.size() - 1; i++) {
    long long buf = 1;
    for (long long j = 0; j < n - s[i].first; j++) buf *= 10;
    if (s[i].first == s[i + 1].first || (s[i].first == 1 && s[i].second == 0)) {
      ans = -1;
      break;
    } else {
      ans += s[i].second * buf;
    }
  }
  cout << ans << endl;
}
