#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> data(N);
  vector<vector<int>> ruru(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> ruru[i][0] >> ruru[i][1];
  }
  for (int i = 0; i < M; i++) {
    if (N != 1 && ruru[i][0] == 1 && ruru[i][1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int k = i + 1; k < M; k++) {
      if (ruru[i][0] == ruru[k][0] && ruru[i][1] != ruru[k][1]) {
        cout << -1 << endl;
        return 0;
      }
      data[(ruru[i][0] - 1)] = (ruru[i][1]);
    }
  }
  int ans;
  if (N == 1) {
    ans = data[0];
  }
  if (N == 2) {
    if (data[0] == 0) {
      data[0] == 1;
    }
    ans = 10 * data[0] + data[1];
  }
  if (N == 3) {
    if (data[0] == 0) {
      data[0] == 1;
    }
    ans = 100 * data[0] + 10 * data[1] + data[2];
  }
  cout << ans << endl;
}
