#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);
  if (s.size() == 1) {
    if (s[0].first == 1 && s[0].second == 0) flag = false;
  } else {
    for (long long i = 0; i < s.size() - 1; i++) {
      if ((s[i].first == s[i + 1].first) ||
          (s[i].first == 1 && s[i].second == 0))
        flag = false;
    }
  }
  if (flag) {
    for (long long i = 0; i < s.size(); i++) {
      long long buf = 1;
      for (long long j = 0; j < n - s[i].first; j++) buf *= 10;
      ans += s[i].second * buf;
    }
    cout << ans << endl;
  } else
    cout << "-1" << endl;
}
