#include <bits/stdc++.h>
using namespace std;
using p = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 0)
      cout << 0 << endl;
    else {
      int ans = pow(10, n - 1);
      cout << ans << endl;
    }
    return 0;
  }
  vector<vector<int>> tmp(n, vector<int>(n));
  vector<int> num(n);
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    tmp.at(s - 1).at(num.at(s - 1)) = c;
    num.at(s - 1)++;
  }
  vector<int> set(n, 9);
  for (int i = 0; i < (n); ++i) {
    if (num.at(i) == 0) {
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
      set.at(i) = 0;
    } else {
      for (int j = 0; j < (num.at(i)); ++j) {
        set.at(i) = min(tmp.at(i).at(j), set.at(i));
      }
    }
  }
  int ans = 0, de = pow(10, n - 1);
  for (int i = 0; i < (n); ++i) {
    if (set.at(i) == 0 && i == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans += set.at(i) * de;
    de /= 10;
  }
  cout << ans << endl;
  return 0;
}
