#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
int main() {
  int n, m;
  cin >> n >> m;
  int max = int(pow(10, n + 1));
  int min = int(pow(10, n) - 1);
  vector<P> sc(m);
  for (int i = 0; i < (m); ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  bool judge = true;
  for (int num = min; num < max; num++) {
    judge = true;
    for (int i = 0; i < (n); ++i) {
      int s = sc[i].first;
      int c = sc[i].second;
      if (num / int(pow(10, n - s)) % 10 != c) {
        judge = false;
        break;
      }
    }
    if (judge) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
