#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    p[i] = make_pair(s, c);
  }
  sort(p.begin(), p.end());
  vector<int> ans(n, -1);
  vector<bool> ok(n, false);
  for (int i = 0; i < m; i++) {
    if (p[i].first == 1) {
      if (p[i].second == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        if (ok[0] == false)
          ans[0] = p[i].second;
        else {
          if (ans[0] == p[i].second)
            continue;
          else {
            cout << -1 << endl;
            return 0;
          }
        }
        ok[0] = true;
      }
    } else if (p[i].first == 2) {
      if (ok[1] == false)
        ans[1] = p[i].second;
      else {
        if (ans[1] == p[i].second)
          continue;
        else {
          cout << -1 << endl;
          return 0;
        }
      }
      ok[1] = true;
    } else if (p[i].first == 3) {
      if (ok[2] == false)
        ans[2] = p[i].second;
      else {
        if (ans[2] == p[i].second)
          continue;
        else {
          cout << -1 << endl;
          return 0;
        }
      }
      ok[2] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) {
      if (i == 0)
        ans[i] = 1;
      else
        ans[i] = 0;
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i];
  cout << endl;
  return 0;
}
