#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  int x, y;
  if (n == 1)
    x = 1, y = 9;
  else if (n == 2)
    x = 10, y = 99;
  else if (n == 3)
    x = 100, y = 999;
  for (int i = 0; i <= 1000; i++) {
    if (x <= i && i <= y) {
      vector<int> tmp;
      int t = i;
      while (t > 0) {
        tmp.push_back(t % 10);
        t /= 10;
      }
      bool f = false;
      for (int j = 0; j < m; j++) {
        if (tmp[n - v[j].first] != v[j].second) {
          f = true;
          break;
        }
      }
      if (!f) {
        cout << i << '\n';
        return 0;
      }
    }
  }
  cout << -1 << '\n';
}
