#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m, vector<int>(2, 0));
  for (int i = 0; i < m; i++) {
    cin >> v.at(i).at(0);
    cin >> v.at(i).at(1);
  }
  vector<int> vi(n, 0);
  for (int i = 0; i < v.size(); i++) {
    int digit = v.at(i).at(0) - 1;
    int num = v.at(i).at(1);
    if (vi.at(digit) != 0 && vi.at(digit) != num) {
      cout << -1 << endl;
      return 0;
    }
    vi.at(digit) = num;
  }
  if (vi.size() > 1 && vi.at(0) == 0) vi.at(0) = 1;
  int ans;
  for (int i = 0; i < vi.size(); i++) {
    ans += vi.at(i) * pow(10, vi.size() - 1 - i);
  }
  cout << ans << endl;
  return 0;
}
