#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(n, vector<int>());
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    d[s - 1].emplace_back(c);
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    vector<int> a = d[i];
    a.erase(unique(a.begin(), a.end()), a.end());
    if (a.size() > 1) {
      ans = -1;
      break;
    }
    if (a.size() == 0) {
      if (ans == 0)
        ans = 1;
      else
        ans *= 10;
    } else {
      if (ans == 0 && a[0] == 0) {
        ans = -1;
        break;
      }
      ans = 10 * ans + a[0];
    }
  }
  cout << ans << endl;
}
