#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  int sc[m][2];
  bool flag = 1;
  vector<int> c(3);
  for (int i = 0; i < m; i++) {
    cin >> sc[i][0] >> sc[i][1];
  }
  for (int i = 0; i < m; i++) {
    if ((sc[i][0] == 1) && (sc[i][1] == 0)) {
      ans = 0;
    }
    for (int j = i + 1; j < m; j++) {
      if (ans == 0 && sc[j][0] != 1) {
        flag = 0;
        break;
      }
      if (sc[i][0] == sc[j][0] && sc[i][1] != sc[j][1]) {
        flag = 0;
        break;
      }
    }
  }
  if (flag) {
    for (int i = 0; i < m; i++) {
      c[sc[i][0] - 1] = sc[i][1];
    }
    if (n == 3) {
      ans = c[2] + c[1] * 10 + c[0] * 100;
    } else if (n == 2) {
      ans = c[1] + c[0] * 10;
    } else {
      ans = c[0];
    }
  }
  cout << ans << endl;
}
