#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int S = 0;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> c[i];
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << "-1" << endl;
          break;
        } else if (c[i] == c[j]) {
          c[i] = 0;
        }
      }
    }
    S += c[i] * pow(10, (N - s[i]));
  }
  if (S / pow(10, N) == 0) {
    cout << "-1" << endl;
  } else {
    cout << S << endl;
  }
}
