#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  int j = 0;
  vector<int> s(M), c(M);
  for (int i = 0; i < (int)M; ++i) cin >> s[i] >> c[i];
  for (int k = 0; k < (int)1000; ++k) {
    string str = to_string(k);
    if (str.size() == N) {
      int j = 0;
      for (int i = 0; i < (int)M; ++i) {
        if (str[s[i] - 1] == c[i] + '0') {
          ++j;
        }
      }
      if (j == N) {
        cout << k << endl;
        goto xyz;
      }
    }
  }
  cout << -1 << endl;
xyz:;
}
