#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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 num;
  bool ans;
  for (num = 0; num < pow(10, N); num++) {
    ans = true;
    vector<int> d(3, 10);
    d[0] = num % 10;
    if (num >= 10) d[1] = num / 10 % 10;
    if (num >= 100) d[2] = num / 100 % 10;
    for (int i = 0; i < M; i++) {
      if (d[3 - s[i]] != c[i]) ans = false;
    }
    if (ans) break;
  }
  if (ans)
    cout << num << endl;
  else
    cout << -1 << endl;
  return 0;
}
