#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, i;
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<pair<int, int>> sm(m);
  map<int, int> mp;
  int ans = 0;
  for (i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    sm[i] = make_pair(s[i], c[i]);
    mp[s[i]] = c[i];
  }
  sort(sm.begin(), sm.end());
  bool ha = true;
  for (i = 0; i < m - 1; ++i) {
    if (sm[i].first == sm[i + 1].first) {
      if (sm[i].second != sm[i].second) {
        ha = false;
      }
    }
  }
  if (ha == true) {
    for (auto p : mp) {
      if (n > p.first) {
        ans += pow(10, (n - p.first)) * p.second;
      } else {
        ans += p.second;
      }
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
