#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > sc(M);
  int Min = 4;
  for (int i = 0; i < M; i++) {
    cin >> sc[i].first >> sc[i].second;
    sc[i].first--;
    Min = min(Min, sc[i].first);
  }
  for (int i = 0; i < M; i++) {
    if (sc[i].first == Min && sc[i].second == 0) {
      cout << -1 << endl;
      return (0);
    }
  }
  sort(sc.begin(), sc.end(), greater<pair<int, int> >());
  vector<bool> ok(3, true);
  string ans = "000";
  for (int i = 0; i < M; i++) {
    if (ok[sc[i].first] || ans[sc[i].first] == '0' + sc[i].second) {
      ans[sc[i].first] = '0' + sc[i].second;
    } else {
      cout << -1 << endl;
      return 0;
    }
    ok[sc[i].first] = false;
  }
  cout << ans << endl;
}
