#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
const long long INFLL = 1LL << 60;
const int INFI = 1000000000;
int main() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  bool flag = true;
  vector<int> v(3, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] == -1)
      v[s] = c;
    else if (c != v[s]) {
      cout << -1 << endl;
      flag = false;
      break;
    }
  }
  if (flag) {
    for (int i = 0; i < 3; i++) {
      if (v[i] == 0)
        ans = -1;
      else if (v[i] == -1)
        ans += 0;
      else
        ans += v[i] * pow(10, 2 - i);
    }
    cout << ans << endl;
  }
}
