#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> minN;
vector<pair<int, int>> sc;
bool isn_dupl(int n, int m) {
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (sc[i].first == sc[j].first && sc[i].second != sc[j].second)
        return false;
    }
    minN[sc[i].first] = sc[i].second;
  }
  return true;
}
int main() {
  cin >> N >> M;
  minN.resize(N + 1, -1);
  sc.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> sc[i].first >> sc[i].second;
  }
  if (isn_dupl(N, M)) {
    if (N >= 2 && minN[1] == 0)
      cout << -1 << endl;
    else {
      for (int i = 1; i <= N; i++) {
        if (minN[i] < 0) {
          if (i == 1)
            cout << 1;
          else
            cout << 0;
        } else
          cout << minN[i];
      }
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
