#include <bits/stdc++.h>
using namespace std;
int pow(int x, int n) {
  if (n == 0) return 1;
  int y = pow(x, n / 2);
  y *= y;
  if (n % 2 == 1) y *= x;
  return y;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> SCs(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    SCs[i].first = s - 1;
    SCs[i].second = c;
  }
  int ceil = pow(10, n);
  int floor = pow(10, n - 1);
  int INF = pow(10, 5);
  int ans = INF;
  for (int i = floor; i < ceil; i++) {
    string str = to_string(i);
    bool allok = true;
    for (auto sc : SCs) {
      char charC = sc.second + '0';
      if (str[sc.first] != charC) {
        allok = false;
      }
    }
    if (allok) ans = min(i, ans);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
