#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  vector<int> vec(b * 2);
  for (int i = 0; i < b * 2; i++) {
    cin >> vec.at(i);
  }
  int count = 0;
  vector<int> vec2(3);
  vec2[0] = 0;
  vec2[1] = 0;
  vec2[2] = 0;
  int error = 0;
  for (int n = 0; n < b * 2; n++) {
    if (n % 2 == 0) {
      if (vec[n] == 1) {
        if (vec2[0] == 0)
          vec2[0] = vec[n + 1] * pow(10, (a - 1));
        else if (vec2[0] > 0) {
          error = vec2[0] - vec[n + 1] * pow(10, (a - 1));
        }
      }
      if (vec[n] == 2) {
        if (vec2[1] == 0)
          vec2[1] = vec[n + 1] * pow(10, (a - 2));
        else if (vec2[1] > 0) {
          error = vec2[1] - vec[n + 1] * pow(10, (a - 2));
        }
      }
      if (vec[n] == 3) {
        if (vec2[2] == 0)
          vec2[2] = vec[n + 1] * pow(10, (a - 3));
        else if (vec2[2] > 0) {
          error = vec2[2] - vec[n + 1] * pow(10, (a - 3));
        }
      }
    }
  }
  count = vec2[0] + vec2[1] + vec2[2];
  if (error > 0)
    cout << "-1" << endl;
  else
    cout << count << endl;
}
