#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vi = vector<int>;
using vs = vector<string>;
using gi = greater<int>;
int main() {
  int keta, M;
  cin >> keta >> M;
  vi ans(keta, 0);
  vi s(M), c(M);
  for (int i = 0; i < (int)(M); i++) cin >> s.at(i) >> c.at(i);
  for (int i = 0; i < (int)(M); i++) {
    for (int j = 0; j < (int)(M); j++) {
      if (s.at(i) == s.at(j) && i != j) {
        if (c.at(i) != c.at(j)) {
          cout << "-1" << endl;
          goto end;
        }
      }
    }
  }
  for (int i = 0; i < (int)(M); i++) ans.at(s.at(i) - 1) = c.at(i);
  if (keta == 3) {
    if (ans.at(0) == 0 && ans.at(1) == 0)
      cout << "10" << ans.at(2) << endl;
    else if (ans.at(0) == 0)
      cout << "1" << ans.at(1) << ans.at(2) << endl;
    else
      cout << ans.at(0) << ans.at(1) << ans.at(2) << endl;
  } else if (keta == 2) {
    if (ans.at(0) == 0)
      cout << "1" << ans.at(1) << endl;
    else
      cout << ans.at(0) << ans.at(1) << endl;
  } else
    cout << ans.at(0) << endl;
end:;
}
