#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  cin >> b;
  vector<int> keta(b);
  vector<int> vec(b);
  vector<int> error(a);
  for (int i = 0; i < b; i++) {
    cin >> keta[i];
    cin >> vec[i];
  }
  int count = 0;
  vector<int> chop(a);
  for (int i = 0; i < b; i++) {
    if (error[keta[i]] == 0) {
      count = count + vec[i] * pow(10, a - keta[i]);
      error[keta[i]] = vec[i];
    } else {
      chop[i] = error[keta[i]] - vec[i];
    }
  }
  int chopchop = 0;
  for (int i = 0; i < a; i++) {
    chopchop = chopchop + chop[i];
  }
  if (count == 0)
    cout << "-1" << endl;
  else if (chopchop == 0)
    cout << count << endl;
  else
    cout << "-1" << endl;
}
