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