#include <bits/stdc++.h>
int64_t inf = 1000000007;
int64_t giant = 4000000000000000037;
using namespace std;
int64_t cup(int64_t xxx, int64_t yyy) { return (xxx + yyy - 1) / yyy; }
int n, m;
void input() { cin >> n >> m; }
int main() {
  input();
  vector<set<int>> dat;
  dat.resize(4);
  vector<int> ans(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dat[a - 1].insert(b);
  }
  for (int i = 0; i < n; i++) {
    if (dat[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    }
    if (dat[i].size() == 1) {
      ans[i] = *begin(dat[i]);
    }
    if (dat[i].size() == 0) {
      ans[i] = 0;
      if (i == 0) ans[i]++;
    }
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
  }
  return 0;
}
