#include <bits/stdc++.h>
using namespace std;
int main() {
  multimap<int, int> mp;
  int n, m;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    mp.emplace(a, b);
  }
  string str;
  bool flag = 0;
  for (int i = 0; i < 1000; i++) {
    str = to_string(i);
    if (str.length() == n) {
      for (auto& x : mp) {
        if (str.at(x.first - 1) - '0' != x.second) {
          flag = 0;
          break;
        } else {
          flag = 1;
        }
      }
      if (flag) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
