#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  vector<int> me(3, 999);
  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> data(2, vector<int>(m));
  for (int i = 0; i < (m); ++i) cin >> data[0][i] >> data[1][i];
  for (int i = 0; i < (m); ++i) {
    if (me[2 - (data[0][i] - 1)] == 999 ||
        me[2 - (data[0][i] - 1)] == data[1][i]) {
      me[2 - (data[0][i] - 1)] = data[1][i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (me[2 - (n - 1)] == 999) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) {
    if (me[i] != 999) ans += me[i] * pow(10, i);
  }
  cout << ans << endl;
  return 0;
}
