#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int MINF = 1e9;
const int MOD = 1e9 + 7;
using vi = vector<int>;
using vii = vector<vi>;
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
T GCD(T a, T b) {
  return b ? GCD(b, a % b) : a;
}
template <typename T>
T LCM(T a, T b) {
  return a * b / GCD(a, b);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  sort((sc).begin(), (sc).end());
  for (int i = 1; i < m; i++) {
    if ((sc[i].first == sc[i - 1].first) &&
        (sc[i].second != sc[i - 1].second)) {
      cout << -1 << endl;
      return 0;
    } else if (sc[0].first == 1 && sc[0].second == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (m == 1) {
    if (sc[0].first == 1 && sc[0].second == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  sc.erase(unique((sc).begin(), (sc).end()), sc.end());
  vi ans(n);
  for (int i = 0; i < sc.size(); i++) {
    ans[sc[i].first - 1] = sc[i].second;
  }
  if (ans[0] == 0) ans[0] = 1;
  for (int i = 0; i < (n); i++) cout << ans[i];
  cout << endl;
  return 0;
}
