#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  bool ok = false;
  for (int i = 0; i < 10; i++) {
    int keta = 3;
    string S;
    S.push_back(i + '0');
    if (i == 0) keta--;
    for (int j = 0; j < 10; j++) {
      S.push_back(j + '0');
      if (i == 0 && j == 0) keta--;
      for (int k = 0; k < 10; k++) {
        S.push_back(k + '0');
        if (keta != N) break;
        bool flag = true;
        for (int x = 0; x < M; x++) {
          if ((S[s[x]] - '0') != c[x]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << stoi(S) << endl;
          ok = true;
          break;
        }
        S.pop_back();
      }
      if (ok) break;
      S.pop_back();
    }
    if (ok) break;
  }
  if (!ok) cout << -1 << endl;
  return 0;
}
