#include <bits/stdc++.h>
using namespace std;
void Main() {
  int N, M;
  cin >> N >> M;
  map<int, int> digitNum;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (digitNum.count(s) != 0 && digitNum[s] != c) {
      cout << -1 << endl;
      return;
    }
    digitNum.insert(make_pair(s, c));
  }
  if (N == 1) {
    if (digitNum.size() == 0) {
      cout << 0 << endl;
      return;
    } else {
      auto e = digitNum.begin();
      cout << (e->second) << endl;
      return;
    }
  } else if (N == 2) {
    if (digitNum.size() == 0) {
      cout << 10 << endl;
      return;
    } else if (digitNum.size() == 1) {
      if (digitNum.count(1) == 1) {
        if (digitNum[1] == 0) {
          cout << -1 << endl;
          return;
        } else {
          cout << digitNum[1] << 0 << endl;
          return;
        }
      } else {
        cout << 1 << digitNum[2] << endl;
        return;
      }
    } else {
      if (digitNum[1] == 0) {
        cout << -1 << endl;
        return;
      } else {
        cout << digitNum[1] << digitNum[2] << endl;
        return;
      }
    }
  } else {
    if (digitNum.size() == 0) {
      cout << 100 << endl;
      return;
    } else if (digitNum.size() == 1) {
      if (digitNum.count(1) == 1) {
        if (digitNum[1] == 0) {
          cout << -1 << endl;
          return;
        } else {
          cout << digitNum[1] << 0 << 0 << endl;
          return;
        }
      } else if (digitNum.count(2) == 1) {
        cout << 1 << digitNum[2] << 0 << endl;
        return;
      } else {
        cout << 1 << 0 << digitNum[3] << endl;
        return;
      }
    } else if (digitNum.size() == 2) {
      if (digitNum.count(1) == 0) {
        cout << 1 << digitNum[2] << digitNum[3] << endl;
        return;
      } else if (digitNum.count(2) == 0) {
        if (digitNum[1] == 0) {
          cout << -1 << endl;
          return;
        } else {
          cout << digitNum[1] << 0 << digitNum[3] << endl;
          return;
        }
      } else {
        if (digitNum[1] == 0) {
          cout << -1 << endl;
          return;
        } else {
          cout << digitNum[1] << digitNum[2] << 0 << endl;
          return;
        }
      }
    } else {
      if (digitNum[0] == 0) {
        cout << -1 << endl;
        return;
      } else {
        cout << digitNum[1] << digitNum[2] << digitNum[3] << endl;
      }
    }
  }
  return;
}
int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
