#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p.at(i).first >> p.at(i).second;
  }
  string n = "000";
  int h = 0;
  int f = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (p.at(i).first == p.at(j).first) {
        if (p.at(i).second != p.at(j).second) {
          f = max(f, p.at(i).first);
          h++;
          break;
        } else {
          string str = to_string(p.at(i).second);
          n.at(p.at(i).first - 1) = str.at(0);
          f = max(f, p.at(i).first);
        }
      } else {
        string str = to_string(p.at(i).second);
        n.at(p.at(i).first - 1) = str.at(0);
        f = max(f, p.at(i).first);
      }
    }
    if (h != 0) {
      cout << "-1" << endl;
      break;
    }
  }
  if (h != 0 && N == f) {
    if (h == 0 && n.at(0) != '0' && f == 3) {
      cout << n << endl;
    } else if (h == 0 && n.at(0) == '0' && f == 3) {
      cout << '1' << n.at(1) << n.at(2) << endl;
    } else if (h == 0 && n.at(1) != '0' && f == 2) {
      cout << n.at(1) << n.at(2) << endl;
    } else if (h == 0 && n.at(1) == '0' && f == 2) {
      cout << '1' << n.at(2) << endl;
    } else if (h == 0 && n.at(2) != '0' && f == 1) {
      cout << n.at(2) << endl;
    } else if (h == 0 && n.at(2) == '0' && f == 1) {
      cout << n.at(2) << endl;
    } else if (h == 0) {
      cout << "-1" << endl;
    }
  } else if (h != 0 && f < N) {
    if (h == 0 && n.at(1) != '0' && f == 2) {
      cout << '1' << n.at(1) << n.at(2) << endl;
    } else if (h == 0 && n.at(1) == '0' && f == 2) {
      cout << '1' << n.at(1) << n.at(2) << endl;
    } else if (h == 0 && f == 1 && N == 3) {
      cout << "10" << n.at(2) << endl;
    } else if (h == 0 && n.at(2) != '0' && f == 1 && N == 2) {
      cout << '1' << n.at(2) << endl;
    } else if (h == 0) {
      cout << "-1" << endl;
    }
  }
}
