#include <bits/stdc++.h>
using namespace std;
int dig[3];
bool done[3];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int s, x;
    cin >> s >> x;
    --s;
    if (done[s] && dig[s] != x) {
      cout << -1 << '\n';
      return 0;
    }
    done[s] = 1;
    dig[s] = x;
  }
  bool v = false;
  for (int i = 0; i < n; ++i) {
    v |= dig[i] != 0;
    if (!v) {
      if (done[i]) {
        cout << -1 << '\n';
        return 0;
      }
      dig[i] = 1;
    }
  }
  for (int i = 0; i < n; ++i) cout << dig[i];
  cout << '\n';
}
