#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > s(m);
  int sum = 0;
  for (int i = (0); i < (m); ++i) {
    cin >> s[i].first >> s[i].second;
  }
  for (int i = (0); i < (m); ++i)
    for (int j = (0); j < (m); ++j) {
      if (i == j) continue;
      if (s[i].first == s[j].first && s[i].second == s[j].second) {
        s[j].first = 0;
        s[j].second = 0;
      }
      if (s[i].first == s[j].first) {
        cout << "-1" << endl;
        return 0;
      }
    }
  for (int i = (0); i < (m); ++i) {
    sum += pow(10, n - s[i].first) * s[i].second;
  }
  if (sum)
    cout << sum << endl;
  else
    cout << "-1" << endl;
  return 0;
}
