#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
  }
  int ans[N];
  for (int i = 0; i < N; ++i) {
    ans[i] = -1;
  }
  bool none = false;
  for (int i = 0; i < M; ++i) {
    if (ans[s[i] - 1] == -1) {
      ans[s[i] - 1] = c[i];
    } else {
      if (ans[s[i] - 1] != c[i]) {
        none = true;
        break;
      }
    }
  }
  if (none) {
    cout << "-1" << endl;
    return 0;
  }
  int fin = 0;
  if (N == 1) {
    if (ans[0] != -1) {
      fin = ans[0];
    } else {
      fin = 0;
    }
    cout << fin << endl;
  } else if (N == 2) {
    if (ans[0] != -1 && ans[0] != 0) {
      fin += 10 * ans[0];
    } else if (ans[0] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (ans[1] != -1) {
      fin += ans[1];
    }
    cout << fin << endl;
  } else {
    if (ans[0] != -1 && ans[0] != 0) {
      fin += 100 * ans[0];
    } else if (ans[0] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (ans[1] != -1) {
      fin += 10 * ans[1];
    }
    if (ans[2] != -1) {
      fin += ans[2];
    }
    cout << fin << endl;
  }
}
