#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> sc;
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    sc.emplace_back(s, c);
  }
  sort(sc.begin(), sc.end());
  vector<int> num(n);
  for (int i = (0); i < (n); ++i) {
    num[i] = 0;
  }
  for (int i = (0); i < (m); ++i) {
    if (n != 1 && sc[i].first == 1 && sc[i].second == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (i < m - 1 && sc[i].first == sc[i + 1].first &&
        sc[i].second != sc[i + 1].second) {
      cout << "-1" << endl;
      return 0;
    }
    num[sc[i].first - 1] = sc[i].second;
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    ans = 10 * ans + num[i];
  }
  cout << ans << endl;
  return 0;
}
