#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  long long s[1000], c[1000];
  for (long long(i) = 0; (i) < (M); (i)++) {
    cin >> s[i] >> c[i];
  }
  for (long long(i) = 0; (i) < (1000); (i)++) {
    bool a = true;
    for (long long(j) = 0; (j) < (M); (j)++) {
      if (to_string(i)[s[j] - 1] != to_string(c[j])[0]) break;
      if (j == M - 1) {
        if (to_string(i).length() == N) {
          cout << i;
          return 0;
        }
      }
    }
  }
  cout << -1;
}
