#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > A(M);
  for (int i = 0; i < (int)(M); i++)
    cin >> A.at(i).first >> A.at(i).second, A.at(i).first--;
  for (int i = 0; i <= 2000; i++) {
    string s = to_string(i);
    if (s.size() != N) continue;
    bool l = true;
    for (int j = 0; j < (int)(M); j++) {
      if (s.at(A.at(j).first) - '0' != A.at(j).second) {
        l = false;
      }
      if (l) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
