#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++) cin >> sc[i].first >> sc[i].second;
  bool can = false;
  int tmp = 0;
  if (N == 1) {
    for (int i = 0; i < M; i++) {
      if (i == 0)
        tmp += sc[i].second;
      else {
        if (tmp != sc[i].second) break;
        can = true;
      }
    }
  } else {
    sort(sc.begin(), sc.end());
    for (int i = 0; i < M; i++) {
      if (i > 0 && sc[i].first == sc[i - 1].first &&
          sc[i].second != sc[i - 1].second) {
        can = false;
        break;
      }
      can = true;
      if (i >= 0 && sc[i].first != sc[i - 1].first) {
        tmp += sc[i].second * pow(10, 3 - sc[i].first);
      }
    }
  }
  if (can)
    cout << tmp << endl;
  else
    cout << -1 << endl;
}
