#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int tmp = c.at(0);
  if (n == 1) {
    for (int i = 0; i < (int)(m); i++) {
      if (tmp != c.at(i)) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << tmp << endl;
    return 0;
  }
  int ans = 0;
  if (n == 2 || n == 3) {
    int tmp_1 = 10;
    int tmp_2 = 10;
    int tmp_3 = 10;
    for (int i = 0; i < (int)(m); i++) {
      if (s.at(i) == 1) {
        if (tmp_1 == 10) {
          tmp_1 = c.at(i);
        } else {
          if (tmp_1 != c.at(i)) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      if (s.at(i) == 2) {
        if (tmp_2 == 10) {
          tmp_2 = c.at(i);
        } else {
          if (tmp_2 != c.at(i)) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      if (n == 3) {
        if (s.at(i) == 3) {
          if (tmp_3 == 10) {
            tmp_3 = c.at(i);
          } else {
            if (tmp_3 != c.at(i)) {
              cout << -1 << endl;
              return 0;
            }
          }
        }
      }
    }
    if (n == 2) {
      if (tmp_1 == 10)
        ans += 10;
      else
        ans += tmp_1 * 10;
      if (tmp_2 == 10)
        ans += 0;
      else
        ans += tmp_2;
    }
    if (n == 3) {
      if (tmp_1 == 10)
        ans += 100;
      else
        ans += tmp_1 * 100;
      if (tmp_2 == 10)
        ans += 0;
      else
        ans += tmp_2 * 10;
      if (tmp_3 == 10)
        ans += 0;
      else
        ans += tmp_3;
    }
    if (tmp_1 == 0) ans = -1;
  }
  cout << ans << endl;
  return 0;
}
