#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];
  }
  int ans = -1;
  for (int i = 1; i < pow(10, N); i++) {
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if ((i / int(pow(10, 3 - s[j]))) % 10 != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag && i >= pow(10, N - 1)) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
