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