#include <bits/stdc++.h>
using namespace std;
vector<pair<int, bool>> a(10);
int main() {
  int n, m, s, c;
  vector<pair<int, int>> b(10);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> b[i].first >> b[i].second;
  for (int i = 0; i < m; i++) {
    s = b[i].first - 1;
    c = b[i].second;
    if (a[s].first != c && a[s].second) {
      cout << "-1\n";
      return 0;
    } else {
      a[s].first = c;
      a[s].second = true;
    }
  }
  bool start = false;
  for (int i = 0; i < n; i++) {
    if (a[i].first) start = true;
    if (start) {
      cout << a[i].first;
    }
  }
  if (!start) cout << "-1\n";
}
