#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) cin >> s.at(i) >> c.at(i);
  bool ans = true;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          ans = false;
          break;
        }
      }
    }
    if (ans == false) break;
  }
  for (int i = 0; i < m; ++i) {
    if (c.at(i) == 0) {
      if (s.at(i) == 1) {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    int ans_num = 0;
    vector<int> arr(m + 1, -1);
    for (int i = 0; i < m; ++i) {
      arr.at(s.at(i)) = c.at(i);
    }
    if (n == 3) {
      if (arr.at(1) != -1) {
        ans_num += arr.at(1) * 100;
      } else {
        ans_num += 100;
      }
      if (arr.at(2) != -1) {
        ans_num += arr.at(2) * 10;
      }
      if (arr.at(3) != -1) {
        ans_num += arr.at(3);
      }
    } else if (n == 2) {
      if (arr.at(1) != -1) {
        ans_num += arr.at(1) * 10;
      } else {
        ans_num += 10;
      }
      if (arr.at(2) != -1) {
        ans_num += arr.at(2);
      }
    } else {
      if (arr.at(1) != -1) {
        ans_num += arr.at(1);
      } else {
        ans_num += 1;
      }
    }
    cout << ans_num << endl;
  } else {
    cout << -1 << endl;
  }
}
