#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, s, c;
  cin >> n >> m;
  map<int, set<int> > mp;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    mp[s].insert(c);
  }
  bool flag = false;
  int maxm = INT_MIN;
  for (auto &i : mp) {
    if (i.second.size() > 1 ||
        (*i.second.begin() == 0 && i.first == 1 && n > 1)) {
      flag = true;
      break;
    }
    maxm = max(maxm, i.first);
  }
  if (flag) {
    cout << -1;
  } else {
    int num = 0;
    for (auto &i : mp) {
      num += int(pow(10, maxm - i.first) + 0.5) * *i.second.begin();
    }
    cout << num;
  }
  cout << "\n";
  return 0;
}
